简体   繁体   English

如何暂停足够长的时间以使cmd.exe退出?

[英]How to pause long enough that cmd.exe exits?

I am updating TortoiseGit repository using the following code (which works) in command line file (MyTestRepo.cmd): 我正在命令行文件(MyTestRepo.cmd)中使用以下代码(有效)更新TortoiseGit存储库:

cd c:\MyTortoiseGitRepo
git.exe pull --progress -v --no-rebase "origin"

In PowerShell I am calling this file using the following code: 在PowerShell中,我使用以下代码调用此文件:

$TestPull = Start-Job { Invoke-Item C:\MyTests\MyTestRepo.cmd }
Wait-Job $TestPull
Receive-Job $TestPull

The above code does work but it is not waiting long enough for the CMD file to finish running and exit cmd.exe to exit before moving on to the next line of code. 上面的代码可以正常工作,但是等待足够长的时间才能使CMD文件完成运行并退出cmd.exe,然后继续进行下一行代码。

What better way to you have to wait for the cmd.exe process to finish before moving on? 有什么更好的方式让您继续前进之前必须等待cmd.exe进程完成?

Invoke-Item doesn't support waiting. Invoke-Item不支持等待。 You can use the call operator & . 您可以使用呼叫运算符& Ex: 例如:

$TestPull = Start-Job { & "C:\MyTests\MyTestRepo.cmd" }

Or Start-Process -Wait : Start-Process -Wait

$TestPull = Start-Job { Start-Process -FilePath "C:\MyTests\MyTestRepo.cmd" -Wait }

Start-Process will show the cmd-window when the script is excecuted by a user. 当用户执行脚本时, Start-Process将显示cmd窗口。 This can be suppressed by adding - NoNewWindow`. 这可以通过添加抑制- NoNewWindow`。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM