[英]Windows Batch File - Batch File stops executing mid way after a command that takes a while to complete
Following are the contents of the file "vs.bat" 以下是文件“vsbat”的内容
call "C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat"
call path.bat
dea usev bis
cd ana
call b-env-i.bat
When I execute this batch file, execution stops after the following step. 执行此批处理文件时,执行在以下步骤后停止。
dea usev bis
Can anyone please help in pointing out what went wrong here and how I can get all the commands to execute. 任何人都可以帮助指出这里出了什么问题以及我如何能够执行所有命令。 Note that the aforementioned command (dea usev bis) works fine (both in the batch and if executed separately).
请注意,上述命令(dea usev bis)工作正常(在批处理中,如果单独执行)。 dea is the name of the executable and "usv bis" are runtime parameters to the "dea" exe.
dea是可执行文件的名称,“usv bis”是“dea”exe的运行时参数。
I'm running Windows 7. 我正在运行Windows 7。
Clarification: 澄清:
When I run vs.bat, after the third call "dea usev bis" has executed successfully, the batch file stops executing further. 当我运行vsbat时,在第三次调用“dea usev bis”成功执行后,批处理文件停止执行。 That is both the following calls (which are part of VS.bat) don't get executed
这是以下调用(它们是VS.bat的一部分)不执行
cd ana cd ana
call b-env-i.bat 叫b-env-i.bat
Note that the call "dea usev bis" takes around 20 secs to execute, both when run individually and when run as part of the script. 请注意,调用“dea usev bis”需要大约20秒才能执行,无论是单独运行还是作为脚本的一部分运行。
Update: 更新:
I've tried paxdiablo's suggestions, with the following results: 我尝试了paxdiablo的建议,结果如下:
[C:\dea]for %i in (dea.cmd) do @echo %~$PATH:i
ECHO is on.
[C:\dea]for %i in (dea.bat) do @echo %~$PATH:i
ECHO is on.
[C:\dea]for %i in (dea.exe) do @echo %~$PATH:i
C:\dea\bin\dea.exe
[C:\dea]where dea.exe
C:\dea\bin\dea.exe
C:\dea\bin\dea.exe.1
C:\dea\bin\dea.exe.ia64
When I run it explicitly via the following, I still encounter the same issue 当我通过以下显式运行它时,我仍然遇到同样的问题
c:\dea\bin\dea.exe usev bis
And, as I said earlier, changing the script to call dea
does not fix the issue either. 而且,正如我之前所说,更改脚本以
call dea
也无法解决问题。
Is there anything else that I can try? 还有什么我可以尝试的吗?
It looks like you're trying to call another batch/script file which, if you leave off call
, will simply be chained to rather than called (chained to, in this context, means it doesn't return). 看起来你正试图调用另一个批处理/脚本文件,如果你不通
call
,它将被简单地链接到而不是被调用(链接到,在这种情况下,意味着它不会返回)。 I'd suggest changing that line to: 我建议将该行更改为:
call dea usev bis
By way of example, consider the scripts go2.cmd
: 举个例子,考虑脚本
go2.cmd
:
@echo off
echo %1
and go.cmd
: 和
go.cmd
:
@echo off
call go2 1
go2 2
echo 3
Executing go
will only give you: 执行
go
只会给你:
1
2
because the go2 2
line chains to, rather than calls that script. 因为
go2 2
行链接到,而不是调用那个脚本。 The call go2 1
line, however, works fine. 然而,
call go2 1
线工作正常。
And, even if you have a dea.exe
file, that does not necessarily mean it's the one being run. 而且,即使您有
dea.exe
文件,也不一定意味着它正在运行。 Your script calls dea
so leaves the choice as to what actually gets run to the shell (searching the path, trying different extensions and so on). 您的脚本调用
dea
因此可以选择实际运行到shell的内容(搜索路径,尝试不同的扩展等)。
To check whether or not the thing you're actually calling is a batch file or not, you can do the following. 要检查您实际调用的内容是否是批处理文件,可以执行以下操作。 First, execute the following commends:
首先,执行以下表彰:
echo %PATH%
for %i in (dea.cmd) do @echo %~$PATH:i
for %i in (dea.bat) do @echo %~$PATH:i
for %i in (dea.exe) do @echo %~$PATH:i
(or I think you can just use where dea*
if you're running Win 7+, see here for details). (或者我认为你可以使用
where dea*
如果你正在运行Win 7+,请参阅此处了解详情)。
This will show you if there is a dea.cmd/bat/exe
in your path, and tell you where in the path the relevant directories are. 这会告诉你,如果有一个
dea.cmd/bat/exe
在你的路径,并告诉你在哪里路径相关的目录是。 If there is a script version, it may exist in the path before the exe
version. 如果有脚本版本,它可能存在于
exe
版本之前的路径中。 You can simply examine your %PATH%
environment variable to figure out which directory comes first. 您可以简单地检查
%PATH%
环境变量,以确定首先出现的目录。
Second, if you have the exe
in c:\\dea\\bin
, try running that explicitly from your script with: 其次,如果您在
c:\\dea\\bin
有exe
,请尝试使用以下命令从脚本中显式运行:
c:\dea\bin\dea.exe usev bis
If that returns okay, it adds support to the fact a script version is being used instead. 如果返回正常,则会增加对正在使用脚本版本的支持。
Thirdly, you could just change the script as suggested (add call
) and see if that fixes it. 第三,您可以按照建议更改脚本(添加
call
),看看是否修复了它。 If it is referencing a script, that will fix it. 如果引用的脚本,这将修复它。
If none of those work (and this appears to be the case based on your response that dea
is definitely an exe
file), you need to start looking into exactly where the failure occurs. 如果没有这些工作(这似乎是根据你的回应,此案
dea
绝对是一个exe
文件),你需要开始寻找到确切失败发生。 This can be done by placing an echo
statement in between every single line so that you can see what's causing the issue. 这可以通过在每一行之间放置一个
echo
语句来完成,这样你就可以看到导致问题的原因。 In other words, something like: 换句话说,像:
echo DEBUG a & time <nul:
call "C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat"
echo DEBUG b & time <nul:
call path.bat
echo DEBUG c & time <nul:
dea usev bis
echo DEBUG d & time <nul:
cd ana
echo DEBUG e & time <nul:
call b-env-i.bat
echo DEBUG f & time <nul:
That will both give you timings for the things that do work and hopefully make it obvious what's not working. 这都将让你时刻为做工作,希望使之明显发生了什么不工作的事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.