这是我当前的批处理文件
d:
SET PATH=%PATH%;D:\_Work\Automation\Selenium\_php5.6.14;
IF "%1"=="reports" GOTO reports
IF "%1"=="selenium" GOTO automation
IF "%1"=="phpunit" GOTO automation
IF "%1"=="auto" GOTO automation
IF "%1"=="self" GOTO self
:reports
cd "_Work\Office\Excel"
start /B call "Stored Procedure File List.xlsx"
cd "..\..\TFS\Riley\Main\ReportsSrv"
call ReportsSrv.sln
cd "..\..\..\..\Other\txt"
call "Used Tables.txt"
cd "..\..\Automation\Selenium\Misc Tasks"
call "getTables.php"
call "_getTables-results.sql"
GOTO end
:automation
cd "_Work\Automation\Selenium\_Selenium Server"
start call selenium
cd ../
GOTO end
:self
goto terminate
:terminate
exit
:end
当我运行命令启动报告
时,当我尝试在运行批处理文件后使用命令提示符时,有时会收到以下内容
注意:GOTO end
之后的所有内容都是我的输入,而不是批处理文件。空行是我按 Enter
当我关闭打开的 Excel 窗口时,似乎会发生这种情况。我怀疑这与start/B call“Stored procedure File List.xlsx”
有关。我这样做的原因是因为只要调用“存储过程文件列表.xlsx”
批处理文件就会暂停,直到Excel关闭。
我想知道为什么当我退出 Excel 时命令提示符会在这两个位置之间交换,因为我认为 start/B
在后台运行命令
最佳答案
在不讨论如何启动 xlsx 文件的情况下,我将首先解释其行为。
使用 START/B 选项执行 CALL 将在同一控制台窗口中启动一个新的 cmd.exe 进程。这个新进程与原始 cmd.exe 进程共享 stdin 和 stdout。当您关闭 Excel 时,第二个 cmd.exe 进程仍在运行。
现在有两个进程争夺控制台输入和输出。当您输入命令时,只有一个进程会收到它。
假设父进程收到第一个 [Enter] - 然后打印出正常的提示符。第二个[Enter]被第二个进程接收,并打印其提示符(由于当前目录不同而有所不同)。
如果您发出 EXIT,那么其中一个进程将终止,您将得到一个只有一个进程的普通控制台。
解决该问题的一种方法是使用附加的 EXIT 命令显式启动新命令进程。
start /b cmd /c ""Stored Procedure File List.xlsx" & exit"
但我认为你可以简单地使用
start "" "Stored Procedure File List.xlsx"
如果 START 的第一个参数被引用,则它被解释为窗口标题。因此,您的 xlsx 文件之前有空引号。
关于excel - 为什么命令提示符在两个位置之间切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39650246/