Page 1 of 1

Using variables with spaces crashes batches

Posted: 01 Jul 2010 14:19
by Laraso
Hi, I was trying to create something using batch and I keep running into this same annoying bug... If I tell the batch to do something with a variable that has spaces in it, it doesn't work. It's very hard to explain, so I will just show you an example of what I am doing:

Code: Select all

set /p command="Enter a command: "
%command%


These are two lines from my batch file, and whenever it gets to the %command% part, if there is a space in the variable the whole batch closes. This seems unavoidable and is preventing me from going any further. Is there a way to avoid this? I've tried using quotations, but that only seems to give me syntax errors. :roll:

Re: Using variables with spaces crashes batches

Posted: 01 Jul 2010 15:17
by aGerman
Laraso wrote:These are two lines from my batch file, and whenever it gets to the %command% part, if there is a space in the variable the whole batch closes.


Hmm, not for me. I tried net help and it worked fine.

Would you give an example command, please.

Regards
aGerman

Re: Using variables with spaces crashes batches

Posted: 01 Jul 2010 15:50
by alan_b
I suggest you try this :-

Code: Select all

set /p command="Enter a command: "
ECHO %COMMAND%
%command%


Launch CMD.EXE, run the script and enter whatever you chosen command is,
the right click the display and choose "Select All", then hit ENTER to copy the screen to the paste buffer. Then reply here and use Ctrl'V to copy the paste buffer into the reply so we can see what your problem is.

Alan