我已经安排了一个执行PowerShell脚本的SQLserver代理作业,该脚本调用了批处理进程。 但是,执行PowerShell时,在转到下一个作业步骤之前,并没有等待batch file完成。 我可以做些什么来使它在batch file完成之前等待?
这是命令:
([WMICLASS]"\\SERVER\ROOT\CIMV2:win32_process").Create("cmd.exe /c E:\BatchFiles\First_Batch_File.bat")
Create
方法将返回它创建的进程的ProcessId
。 您可以检查该进程是否以Get-Process
结束
$process = ([WMICLASS]"\\SERVER\ROOT\CIMV2:win32_process").Create("cmd.exe /c E:\BatchFiles\First_Batch_File.bat") while ((Get-Process -Id $process.ProcessId -ErrorAction SilentlyContinue) -ne $null) { write-host "waiting" sleep 2 }