Chain commands on the PowerShell command line (like POSIX sh &&) [duplicate]

落爺英雄遲暮 提交于 2020-07-06 07:09:53

问题


Does PowerShell have an equivalent to this command construct from sh (and derivatives):

$ cmd1 && cmd2

where cmd2 is only run when cmd1 exits sucessfully?

I know you can combine commands with a semicolon. However, this disregards the exit status of commands.


回答1:


There is no direct analog to && or ||. There are several discussions on alternatives though. Here is one example:

conditional execution (&& and ||) in powershell




回答2:


Try this:

$errorActionPreference='Stop'; cmd1; cmd2


来源:https://stackoverflow.com/questions/11104197/chain-commands-on-the-powershell-command-line-like-posix-sh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!