3

I have a powershell script that could be VERY crudely represented by the following.

function startTask
{
    calls external batch script (runs for roughly 10 minutes)
    creates done1.txt
 }
function startTask2
{
    calls batch (runs for roughly 10 minutes)
    creates done2.txt
}
startTask
if done1.txt exists
startTask2
if done2.txt exists
write-host "done"

The issue I am facing is that immediately after calling the first batch file the 2nd batch file gets called. Is there a way to have powershell be aware of when the batch file is done? Side note, I don't have access to the batch file so I am unable to edit it

4

1 回答 1

0

我建议您只使用带有错误/退出代码的 try-catch,而不是从每个任务中编写文本文件:

一个例子:

## D:\Scripts\Temp\exit.ps1 ##
try{
    $null.split()
}
catch
{
    exit 34
}

exit 2
#############################

# launch powershell from cmd 
C:\> powershell -noprofile -file D:\Scripts\Temp\exit.ps1
C:\>echo %errorlevel%
34
于 2014-06-13T21:29:43.637 回答