PDA

View Full Version : ~~



Peegee
06-08-2009, 03:36 PM
I've narrowed it down to this question:

"In a dos prompt batch input file, how do you input a string that has a space?"

Eg (simplied to illustrate the point):

Say you have a file input.txt

input.txt has the following lines

"telephone"
"caterpillar"
"boeing airplane"

If you were to run the following batch:

for /f %%i in (input.txt) do (
@echo %%i
)

You will get the following :

"telephone"
"caterpillar"
"boeing

Where's the " airplane"?? It doesn't get picked up by echo!

However if you typed in dos prompt echo "boeing airplane" it would output:

boeing airplane

aieee~

Namelessfengir
06-08-2009, 05:02 PM
maybe underscore? its been about 4 years since i dealt with dos

Peegee
06-08-2009, 06:19 PM
Underscore makes an underscore

So boeing_airplane becomes boeing_airplane, not boeing airplane.

;D

This is not pressing (I'm writing a script to simplify adding global groups to a user account) but it would simplify my life. Not sure if it would be more efficient unless I were doing multiple identical accounts, but all the same... (http://forums.eyesonff.com/members/leeza.html)

NeoTifa
06-08-2009, 07:59 PM
Could you print the two tokens on the same line? And wtf are you doing with dos anyway?

Peegee
06-08-2009, 08:27 PM
Could you print the two tokens on the same line? And wtf are you doing with dos anyway?

It's for work. I'm not sure what you mean by the first sentence ;o (http://forums.eyesonff.com/members/leeza.html)

o_O
06-09-2009, 01:11 AM
Try this code, I'm not that flash with batch scripting in Windows but it worked for me.
for /f "delims=[]" %%i in (input.txt) do (
@echo %%i
)

Peegee
06-09-2009, 06:13 PM
That did it, but I'm not sure what that means though. Did you specify something or nothing in the delimiter?

o_O
06-10-2009, 01:08 AM
The default delimiter value for the windows shell is "<tab><space>", so the for loop iterates over every value that it can find which is delimited by one of these two characters. By changing the delimiter either to a character you know will never be used or to nothing at all (this is what I did; [] represents a set of no characters) you can force the script to ignore spaces.