1

Trying to use the path to the current script, and the path contains spaces in it. I can't seem to get it to work though:

C:\Test Directory>dir
 Volume in drive C has no label.
 Volume Serial Number is 7486-CEE6

 Directory of C:\Test Directory

08/31/2010  07:28 PM    <DIR>          .
08/31/2010  07:28 PM    <DIR>          ..
08/31/2010  07:28 PM                20 echoit.cmd
08/31/2010  07:28 PM                94 test.cmd
               2 File(s)            114 bytes
               2 Dir(s)  344,141,197,312 bytes free

C:\Test Directory>type echoit.cmd
@echo off
echo %*

C:\Test Directory>type test.cmd
@echo off

for /f "tokens=*" %%a in ('%~dp0\echoit.cmd Hello World') do (
    echo %%a
)

C:\Test Directory>test
'C:\Test' is not recognized as an internal or external command,
operable program or batch file.

C:\Test Directory>

3 Answers 3

2

Change test.cmd to the following:

   @echo off

   for /f "tokens=*" %%a in ('"%~dp0\echoit.cmd" Hello World') do (
    echo %%a
   )

You need to set the entire command, minus arguments, in quotes. The Windows command prompt treats a collection of words as a single command when the entire collection is quoted, that is why you must exclude the Hello World arguments. If you were to include that in the quotes, Windows would treat that as part of the command not as arguments.

Sign up to request clarification or add additional context in comments.

3 Comments

great, now get it to work for 'c:\program files (x86)\' instead of 'c:\Test Directory'
It should work for 'C:\Program Files (x86)' in the same way. What are you seeing?
I did not have tokens=* after adding that and including "" quotes around usage it fixed my spacing problem.
0

Have you tried adding quotes?

for /f "tokens=*" %%a in ('"%~dp0\echoit.cmd" Hello World') do (
    echo %%a
)

Comments

0

how about using ~fs0, ie

C:\Test Directory>type test.cmd
@echo off

for /f "tokens=*" %%a in ('%~fs0\echoit.cmd Hello World') do (
 echo %%a
)

where %~fsI - expands %I to a full path name with short names only

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.