首页 > 解决方案 > 将带有参数的 bat(启动 cmd 窗口并将命令添加到路径)包含在另一个 bat 中

问题描述

我有一个运行命令的 bat 文件:

C:\Windows\System32\cmd.exe /E:ON /V:ON /K ""C:\Program Files (x86)\path\to\the\compilers\script.bat" option1 option2"

它基本上会打开一个 cmd 窗口,其中不同的命令(英特尔编译器等)已经在路径中。然后,在这个命令窗口中,我cd到一个特定的位置,我使用这些 intel 命令如下:

ifort -c -fpp file1.f90
ifort -c -fpp file2.f90
ifort -c -fpp file3.f90
ifort -dll -o libfinal.dll file1.obj file2.obj file3.obj
lib /out:./libfinal.lib file1.obj file2.obj file3.obj
xcopy /s .\libfinal.dll "..\libfinal.dll*" /Y
xcopy /s .\libfinal.lib "..\libfinal.lib*" /Y

它编译(使用ifortintel fortran 编译器,但问题不依赖于它)库并将它们复制到某处。

我会将以上所有内容打包成一个 bat 文件来完成整个工作。我想出了:

call ""C:\Program Files (x86)\path\to\the\compilers\script.bat" option1 option2"
ifort -c -fpp file1.f90
ifort -c -fpp file2.f90
ifort -c -fpp file3.f90
ifort -dll -o libfinal.dll file1.obj file2.obj file3.obj
lib /out:./libfinal.lib file1.obj file2.obj file3.obj
xcopy /s .\libfinal.dll "..\libfinal.dll*" /Y
xcopy /s .\libfinal.lib "..\libfinal.lib*" /Y

但运行它给了我以下信息:

'""C:\Program' is not recognized as an internal or external command

我检查了Command Prompt Error 'C:\Program' is not Recognized as an internal or external command, operable program or batch file但没有成功适应我的情况

评论。 option1并且option2没有空格或任何需要引用的内容,如果我使用call "C:\Program Files (x86)\path\to\the\compilers\script.bat" option1 option2我有以下错误:

The input line is too long.
The syntax of the command is incorrect.

评论。call行的真实内容是:

call "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017.4.210\windows\bin\ipsxe-comp-vars.bat" intel64 vs2015

标签: windowsbatch-filecmdwindows-10

解决方案


推荐阅读