mle*_*les 6 powershell jobs job-scheduling
我有一个程序,我通常在powershell中这样开始:
.\storage\bin\storage.exe -f storage\conf\storage.conf
Run Code Online (Sandbox Code Playgroud)
在后台调用它的正确语法是什么?我试过很多组合,比如:
start-job -scriptblock{".\storage\bin\storage.exe -f storage\conf\storage.conf"}
start-job -scriptblock{.\storage\bin\storage.exe} -argumentlist "-f", "storage\conf\storage.conf"
Run Code Online (Sandbox Code Playgroud)
但没有成功.它也应该在powershell脚本中运行.
该作业将是PowerShell.exe的另一个实例,它不会在相同的路径中启动,因此.
无法正常工作.它需要知道在哪里storage.exe
.
您还必须使用scriptblock中参数列表中的参数.您可以使用内置的args数组或执行命名参数.args方式需要最少量的代码.
$block = {& "C:\full\path\to\storage\bin\storage.exe" $args}
start-job -scriptblock $block -argumentlist "-f", "C:\full\path\to\storage\conf\storage.conf"
Run Code Online (Sandbox Code Playgroud)
命名参数有助于了解应该是什么参数.以下是使用它们的样子:
$block = {
param ([string[]] $ProgramArgs)
& "C:\full\path\to\storage\bin\storage.exe" $ProgramArgs
}
start-job -scriptblock $block -argumentlist "-f", "C:\full\path\to\storage\conf\storage.conf"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7590 次 |
最近记录: |