19

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.

4

2 回答 2

16

尝试使用 /d 参数更改启动目录以像这样启动:

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

start 命令在解析引号时有一些奇怪的地方。

于 2013-09-18T16:29:35.663 回答
11

这是一个已知的功能cmd.exestart.exe. 仅当命令的名称或路径中有空格并且至少有一个参数被引用时,才会发生这种情况。

一种解决方法是将命令替换为call.

start "" CALL "C:\Test Batch\TestBatch.bat" "C:\Users\User Name\down.doc"
于 2013-09-18T18:30:31.033 回答