21

I am trying to run a batch file that's located in:

C:\Test Batch\BatchTest.bat

That will copy a file from another specified location, let's say

C:\Users\UserName\Desktop\Company Downloads\downloadedDoc.doc

I can run the batch file as:

cmd  /c start "" "C:\Test Batch\TestBatch.bat"

And the batch actually does run.

But when I try to add an argument for it to copy like this:

cmd  /c start "" "C:\Test Batch\TestBatch.bat" "C:\Users\User Name\Desktop\Company Downloads\downloadedDoc.doc"

I get:

'C:\Test' is not recognized a an internal or external command, operable program or batch file.

Ultimately the batch file and file to be copied will be specified by a user and will likely have spaces in the names or path. So a simple answer to use paths without spaces will not suffice.

2 Answers 2

17

Try changing the startup directory with the /d argument to start like so:

cmd /c start "" /d"C:\Test Batch\" "TestBatch.bat" "C:\Users\User Name\Desktop\Company Downloads\downloadedDoc.doc"

The start command has some oddities parsing quotes.

4
  • Thank you for the quick reply. I have to get this working today. I tried using the double quotes just as you mentioned above. But now I get a windows popup that says "Windows cannot find 'C:\Test'. Make sure you typed the name correctly, and then try again." I also wonder if this will affect my ability to run this in java using Runtime.exec(String []) where I may get the embedded quotes error.
    – tfontana
    Commented Sep 18, 2013 at 16:52
  • The good thing is that the Runtime.exec(String []) method doesn't mind the extra quotes. But I still get the same error as above. I know its not a typo because I am browsing to those files to get the paths and names in my application. I'm running windows 7 64 bit.
    – tfontana
    Commented Sep 18, 2013 at 17:01
  • Yeah I just gave it a shot and passing a quoted executable path and a quoted argument to start would not work for me with any quote configuration until I used the /d argument to change start's working directory. Updated the answer above.
    – Egg
    Commented Sep 18, 2013 at 17:28
  • Thanks! This works for me from the command prompt. Now I just have to parse out the path and the batch file into separate strings (which is easy enough) and I think I'm good.
    – tfontana
    Commented Sep 18, 2013 at 17:38
13

It's a known feature of cmd.exe which is started by start.exe. This happens only when the command has a space in its name or path and at least one of the arguments is quoted.

A workaround is to replace the command with a call.

start "" CALL "C:\Test Batch\TestBatch.bat" "C:\Users\User Name\down.doc"
2
  • 2
    This should really be the correct answer...the accepted one is too long and requires knowing the working directory beforehand, which for me, is impossible.
    – Billy Cao
    Commented Sep 25, 2021 at 17:41
  • To me it looks like it's not a space in the command path/name, rather has it to be quoted to cause that strange issue…
    – aschipfl
    Commented Oct 9, 2022 at 18:45

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.