Re: DOS Batch File Question

It certainly sounds like CMD.EXE in Windows 7 is a completely different animal and uses command applets under the skin. I make use of the same old commands, but this page sounds like they might just be aliases to command applets. If so, why are some old commands still restricted to short filenames? It also sounds like there is nothing that can be done about the incompatibilities.


Additionally, there is something referred to as extensions, which need to be enabled for some commands to work as expected! How do you know if extensions are enabled?

By the way, the Vinux 3.0 Virtual Edition has been released! I am downloading right now. Will forward release in next message.

Don Marang

--------------------------------------------------
From: "Martin Slack" <m.g.slack@xxxxxxxxxxxx>
Sent: Friday, July 02, 2010 5:00 PM
To: <programmingblind@xxxxxxxxxxxxx>
Subject: Re: DOS Batch File Question

Hi Don,

I wonder whether you are running PowerShell under Windows7, as indicated here:

http://commandwindows.com/windows7-commands.htm

 Martin


----- Original Message ----- From: "Donald Marang" <donald.marang@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Friday, July 02, 2010 5:49 PM
Subject: Re: DOS Batch File Question


Here is my version of your batch file. The %AppData% should pickup the difference between XP and Vista/Windows 7 file locations. I also attempted to remove the '/L' and make the match string be a regular expression and have a trailing '.*' so it would match the entire line whether it was '="false"' or '="true"' at the end of the line. I also attempted to remove all paths and run from that directory. I also renamed the file, prefs.ini, in case it could only handle short file names. No matter what I tried, I always got a synntax error. I think there is no longer a need for this batch file, since another solution has been found. I think he will be releasing his Vinux 3.0 Virtual Edition package later today.


@echo off
:: Make a backup
copy %AppData%\VMware\preferences.ini %AppData%\VMware\preferences.bak
findstr /I /L /V "pref.hotkey.shift" %AppData%\VMware\preferences.ini > %AppData%\VMware\temp.txt
erase %AppData%\VMware\preferences.ini
ren %AppData%\VMware\temp.txt %AppData%\VMware\preferences.ini
:: Append desired hotkey definition
echo pref.hotkey.shift="true" >> %AppData%\VMware\preferences.ini

Don Marang

--------------------------------------------------
From: "Martin Slack" <m.g.slack@xxxxxxxxxxxx>
Sent: Thursday, July 01, 2010 2:59 PM
To: <programmingblind@xxxxxxxxxxxxx>
Subject: Re: DOS Batch File Question

This is the batch file I use (called remove.bat) to remove a line which matches a string command line parameter:

@echo off
findstr /I /L /V "%1" phones.txt > temp
erase phones.txt
ren temp phones.txt

So I call remove testString from a command line which can see the batch file. I usually don't include spaces in the testString, but surrounding the parameter with double quotes might get that to work.

phones.txt is my target file. You might want that filename to be a parameter too.

There is absolutely no error checking here, so I usually run a non-inverted findstr command first that just prints out the matches. My goal is always to fiddle the testString to give only one match, since I only want to remove one line at a time. If I get more than one match, I try again.

It would definitely be safer to include the checking stage in the same batch file, so something like this might be called for:

@echo off
findstr /I /L "%1" phones.txt
set reply=""
set /p reply=Continue? (y/n):
if "%reply%"=="n" (exit /b)
findstr /I /L /V "%1" phones.txt > temp
erase phones.txt
ren temp phones.txt

This seems to work (with about five minutes of checking. Let me know how you get on.

 Martin



----- Original Message ----- From: "Donald Marang" <donald.marang@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Thursday, July 01, 2010 2:01 PM
Subject: Re: DOS Batch File Question


I would appreciate looking at your code. I started putting that exact approach together late last night and could not quite get it to work.

I also have a ugly solution using a for /f statement combined with a find statement and the ancient edlin commands. The edlin command only works with short filenames!

Don Marang

--------------------------------------------------
From: "Martin Slack" <m.g.slack@xxxxxxxxxxxx>
Sent: Thursday, July 01, 2010 2:23 AM
To: <programmingblind@xxxxxxxxxxxxx>
Subject: Re: DOS Batch File Question

Hi Don,

To do what you want in a DOS batch file, you need to use find or findstr to pull out the lines you want to remove. Those functions have an option to invert the selection so you can redirect the output, minus the chosen lines, into a temporary file. Then append the new line to that file, and finally rename it to overwrite the original file (or not) as you prefer.

I'm doing something like this myself. Let me know if you need code samples and I'll dig them out.

 Martin


----- Original Message ----- From: "Donald Marang" <donald.marang@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Thursday, July 01, 2010 4:05 AM
Subject: DOS Batch File Question


I was attempting to help someone write a batch file to help configure VMware Player to use a preconfigured Vinux Virtual Machine. We want to modify the %AppData%\VMware\preferences.ini file to set the hotkey combination to Alt + Control + Shift. To do this, I need the batch file to do two things.

1. Delete any lines that contain the word "hotkey" that are currently in the file. Two definitions are not permitted in this file. There are other similar lines that appear in this file, but only this line seems to be processed in the newest versions of the software.

2. Append a line at the bottom of the file to define the desired hotkey with the command:
echo 'pref.hotkey.shift="true"' >> %AppData%\VMware\preferences.ini

Obviously, I know how to get the second task done. Can anybody help me with the first? We would need it to work in XP, Vista and Windows 7. In Linux, I think a simple sed statement would do the trick, like
sed 'hotkey/d' ${AppData}/VMware/preferences.ini

I am just guessing at the above hypothetical syntax as well. I have not attempted anything like that in years.Does anybody know how to modify text files in DOS? I ran across 'munge', which could have accomplished this as long as an additional definitions file was used. I use the past tense since it has not been around for a long time. There must be some such capability to search and destroy! The 'FIND' command can locate the lines. I want them deleted as well.

Don Marang
__________
View the list's information and change your settings at http://www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at http://www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at http://www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at http://www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at http://www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at http://www.freelists.org/list/programmingblind

Other related posts: