Powershell 调用批处理文件并等待其完成

Powershell 调用批处理文件并等待其完成,powershell,batch-file,Powershell,Batch File,我有一个powershell脚本,它可以非常粗略地表示为以下内容 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 done

我有一个powershell脚本,它可以非常粗略地表示为以下内容

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"

我面临的问题是,在调用第一个批处理文件后,第二个批处理文件立即被调用。是否有办法让powershell知道批处理文件何时完成?请注意,我没有访问批处理文件的权限,因此无法对其进行编辑。我建议您使用带有错误/退出代码的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

Start Process
cmdlet与
Wait
switch一起使用我考虑过使用Wait。批处理文件可能需要3到20分钟。我使用wait的问题是,这会保证脚本需要很长时间才能完成。
wait
将确保完成&您将能够逐个顺序调用脚本。但是,这不会是一个开销。这完全取决于脚本的执行时间,与
wait
whather无关。我的道歉可能重复,你是对的,这非常有效!非常感谢。