|
Answer» Hi,
I APOLOGIZE if this has been covered before, but I've been searching for 2 days for a solution to no avail. I've wasted enough time on it, so I'm going to go ahead and ask.
The root of the problem is this:
echo 9> myfile.txt
The 9 (or any single digit for that matter) and the > next to each other cause the command to be interpreted incorrectly.
I've found it easy enough to overcome this by "escaping" the 9, ie:
echo ^9> myfile.txt
However, here's the rub, what I'm actually TRYING to do is echo a variable. The variable is set by the user with the SET /P command. The user is prompted to type in the path to their Flight Simulator INSTALLATION which is then set as the variable %fspath%. To avoid the user having to type the path each time he runs the .bat file, I'm attempting to store it (along with some other variables) in an .ini file. When the .bat file is run, the .ini is copied to temp.bat which is then called by the main .bat to set the variables. Something like this:
:start if not exist myfile.ini goto firstrun copy myfile.ini temp$$$.bat call temp$$$.bat del temp$$$.bat goto menu1
:firstrun set /p fspath=Please type the path to your FS installation: echo set fspath=%fspath%> myfile.ini copy myfile.ini temp$$$.bat call temp$$$.bat del temp$$$.bat goto menu1
The problem is that typically the path to the user's FS installation is "[drive]:\Program Files\Microsoft Games\Flight Simulator 9" and because of the "9" at the end of the directory name, nothing at all gets written to the myfile.ini. Any other directory name seems to work fine.
I need some way "escape" the 9 in %fspath%, but short of instructing the user to insert the caret character before the 9 while typing the path, I'm drawing a blank. Any suggestions?
Thanks, JimTry:
echo 9 > myfile.txt
note the space between 9 and >Quote from: Dusty on October 04, 2007, 12:49:09 AM Try:
echo 9 > myfile.txt
note the space between 9 and >
This will (probably) echo the trailing space too. Try this >myfile.txt echo 9
GrahamYES!! That's exactly what I needed, Graham! Thank you so much. I had no idea you could do that. That actually solved another problem I had too. This batch stores settings "profiles" for starting Flight Simulator and the user is prompted to give each profile a name. My only hope before this was that no one ever chose a name like "Profile 4" because obviously the same problem rears it's ugly HEAD when trying to store the name to the .ini file. Now I don't have to worry about, they can name it whatever they want.
Went through and changed 48 occurances in this 1200+ line batch file and everything works perfectly now. Again, a very sincere thank you.
Dusty, Graham's correct in that the space between the 9 and the > CAUSED the trailing space to be echoed to the .ini file. Oddly enough it still worked throughout the rest of the batch file even though it was effectively calling up the program with "...Flight Simulator 9 \fs9.exe" (note the space). The problem was when the user names or renames a profile the .ini gets completely re-written and echo %fspath% > myfile.ini adds a trailing space each time the variable is echoed so before long I wound up with 10 or 20 trailing spaces after the 9.
Thank you both for your replies, I really appreciate it.
Jim
|