在bash中,&号(&)可用于在后台运行命令,并在命令运行完成之前将交互控制返回给用户。在Powershell中是否有等效的方法来做到这一点?
在bash中的用法示例:
sleep 30 &
在bash中,&号(&)可用于在后台运行命令,并在命令运行完成之前将交互控制返回给用户。在Powershell中是否有等效的方法来做到这一点?
在bash中的用法示例:
sleep 30 &
当前回答
传递给Start-Job的脚本块似乎没有在与Start-Job命令相同的当前目录下执行,因此如果需要,请确保指定完全限定的路径。
例如:
Start-Job { C:\absolute\path\to\command.exe --afileparameter C:\absolute\path\to\file.txt }
其他回答
ps2> start-job {start-sleep 20}
我还没有弄清楚如何实时获得stdout, start-job要求你用get-job轮询stdout
更新:我不能开始工作轻松地做我想要的基本上是bash &操作符。这是我目前为止最好的一招
PS> notepad $profile #edit init script -- added these lines
function beep { write-host `a }
function ajp { start powershell {ant java-platform|out-null;beep} } #new window, stderr only, beep when done
function acjp { start powershell {ant clean java-platform|out-null;beep} }
PS> . $profile #re-load profile script
PS> ajp
传递给Start-Job的脚本块似乎没有在与Start-Job命令相同的当前目录下执行,因此如果需要,请确保指定完全限定的路径。
例如:
Start-Job { C:\absolute\path\to\command.exe --afileparameter C:\absolute\path\to\file.txt }
你可以这样做。
$a = start-process -NoNewWindow powershell {timeout 10; 'done'} -PassThru
如果你想等的话:
$a | wait-process
额外的osx或linux版本:
$a = start-process pwsh '-c',{start-sleep 5; 'done'} -PassThru
示例ping脚本我有。参数作为数组传递:
$1 = start -n powershell pinger,comp001 -pa
博士tl;
Start-Process powershell { sleep 30 }
我已经在PowerShell v1.0中成功地使用了这里描述的解决方案http://jtruher.spaces.live.com/blog/cns!7143DA6E51A2628D!130.entry。在PowerShell v2.0中,这肯定会更容易。