简体   繁体   English

在继续之前,如何让Powershell等到命令完成?

[英]How do I make Powershell wait until a command is done before continuing?

My script uninstalls a Windows Store app before installing the newer version. 在安装较新版本之前,我的脚本会卸载Windows应用商店应用。 I need to make sure the uninstall is finished before installing, so how can I make sure I've waited long enough? 我需要确保在安装之前完成卸载,那么我怎样才能确保我已经等了足够长的时间?

Remove-Appxpackage MyAppName  
# ~wait here~  
Add-Appxpackage .\PathToNewVersion

You can do this with the Start-Job and Wait-Job cmdlets: 您可以使用Start-JobWait-Job cmdlet执行此操作:

Start-Job -Name Job1 -ScriptBlock { Remove-Appxpackage MyAppName }
Wait-Job -Name Job1
Add-Appxpackage .\PathToNewVersion

Start-Job will start a new job process that uninstalls the application. Start-Job将启动卸载应用程序的新作业进程。 Wait-Job will then cause the script to wait until the task is completed before continuing. 然后, Wait-Job将使脚本等待任务完成后再继续。

暂无
暂无

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

相关问题 在继续操作之前,如何让PowerShell等到命令完成? - How can I make PowerShell wait until a command is complete before proceeding? 是否存在PowerShell命令来告诉PS在继续之前不要等待服务启动? - Is there a PowerShell command to tell PS not to wait for a service to start before continuing? Service Fabric Start-ServiceFabricApplicationUpgrade - 如何让 powershell 等待升级成功后再继续 - Service Fabric Start-ServiceFabricApplicationUpgrade - How to make powershell wait for successful upgrade before continuing 在继续执行代码之前,如何等待一系列批处理文件完成? - How do I wait for a series of batch files to complete before continuing with my code execution? 如何使Powershell等待内部命令完成? - How to make Powershell wait on internal command to finish? 使用powershell在继续之前等待特定行出现 - Using powershell to wait for a particular line to appear before continuing 等待直到在Powershell中完成上一个命令 - Wait until previous command is completed in powershell 如何告诉 PowerShell 在开始下一个命令之前等待每个命令结束? - How to tell PowerShell to wait for each command to end before starting the next? 在继续执行脚本之前,如何在文件夹为空之前继续检查文件夹 - How can I keep checking a folder until it is empty before continuing on with the script 如何使我的父母轻松运行此Powershell命令? - how do I make it easy for my parents to run this Powershell command?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM