Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble running a batch file with a space in the path and space in the argument

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.

like image 644
tfontana Avatar asked Sep 18 '13 16:09

tfontana


1 Answers

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.

like image 100
Egg Avatar answered Sep 23 '22 08:09

Egg