我有一个PowerShell 1.0脚本来打开一堆应用程序.第一个是虚拟机,其他是开发应用程序.我希望虚拟机在其他应用程序打开之前完成启动.
在bash我可以说 "cmd1 && cmd2"
这就是我所拥有的......
C:\Applications\VirtualBox\vboxmanage startvm superdooper
&"C:\Applications\NetBeans 6.5\bin\netbeans.exe"
Run Code Online (Sandbox Code Playgroud) &&众所周知难以在谷歌搜索,但我发现的最好的是这篇文章说要使用-and.
不幸的是它没有提供任何更多的信息,我无法找到我应该做的事情-and(再次,一个众所周知的难以搜索)
我正在尝试使用它的上下文是"执行cmd1,如果成功,执行cmd2",基本上这样:
csc /t:exe /out:a.exe SomeFile.cs && a.exe
Run Code Online (Sandbox Code Playgroud)
这应该是一个容易的几个代表谁知道,谢谢!
编辑:如果你只想在一行上运行多个命令,而你不在乎第一个是否失败,你可以使用;我的大多数用途这是好的
例如:kill -n myapp; ./myapp.exe.
已经有问题解决我的问题(我可以让&&在Powershell中工作吗?),但有一点不同.我需要两个命令的OUTPUT.看,如果我只是运行:
(command1 -arg1 -arg2) -and (command2 -arg1)
Run Code Online (Sandbox Code Playgroud)
我不会看到任何输出,而是stderr消息.正如所料,只需输入:
command1 -arg1 -arg2 -and command2 -arg1
Run Code Online (Sandbox Code Playgroud)
给出语法错误.
在我的 React 项目上安装Webpack的过程中,遇到以下问题阻碍了我的进度:
配置 Webpack 的最后一步
npm run build && node ./dist/main.js
Run Code Online (Sandbox Code Playgroud)
Windows Power Shell / Visual Studio Code 上的错误
PS C:\Users\pythonbuddha\Desktop\to_experiment\to-do-list> npm run build && node ./dist/main.js
At line:1 char:15
+ npm run build && node ./dist/main.js
+ ~~
The token '&&' is not a valid statement separator in this version.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : InvalidEndOfLine
Run Code Online (Sandbox Code Playgroud)
承诺配置 webpack 的教程
https://developerhandbook.com/webpack/webpack-4-from-absolute-scratch/
https://developerhandbook.com/webpack/how-to-configure-scss-modules-for-webpack/
Run Code Online (Sandbox Code Playgroud) Technet 关于Windows PowerShell 4.0的about_Logical_Operators声明如下:
Operator Description Example
-------- ------------------------------ ------------------------
-or Logical or. TRUE when either (1 -eq 1) -or (1 -eq 2)
or both statements are TRUE. True
-xor Logical exclusive or. TRUE (1 -eq 1) -xor (2 -eq 2)
only when one of the statements False
is TRUE and the other is FALSE.
Run Code Online (Sandbox Code Playgroud)
似乎都没有进行短路评估.
如何在Windows Powershell 4.0中模仿C# ||或VB ?OrElse
可能的重复:
什么是Bash的&&和||的PowerShell等价物 运营商?
我可以让&&在Powershell中工作吗?
在bash中我./task1.sh && ./task2.sh用来运行task1,然后只要task1没有返回错误代码就运行task2.当我.\task1.bat && .\task2.bat在Powershell中尝试时,我收到错误"令牌&&在此版本中不是有效的分隔符".
Windows Powershell中有&&的等价物吗?
我发现自己将这些链接很多,例如:
do-cmd-one
if($?)
{
do-cmd-two
}
...
Run Code Online (Sandbox Code Playgroud)
然后最后:
if(!$?)
{
exit 1
}
Run Code Online (Sandbox Code Playgroud)
我认为在Powershell中有这种模式,但我不知道。
powershell ×7
syntax ×3
c# ×1
command-line ×1
execution ×1
javascript ×1
reactjs ×1
scripting ×1
vb.net ×1
wait ×1
webpack ×1