我有一个程序,通常在powershell中是这样开始的:
.\storage\bin\storage.exe -f storage\conf\storage.conf
在后台调用它的正确语法是什么?我尝试了许多组合,比如:
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"
但没有成功。此外,它还应该在powershell脚本中运行。
发布于 2013-04-02 23:16:49
该作业将是PowerShell.exe的另一个实例,它将不会在相同的路径中启动,因此.
将无法工作。它需要知道storage.exe
在哪里。
您还必须在scriptblock中使用argumentlist中的参数。您可以使用内置的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"
命名参数有助于了解应该是什么参数。下面是它使用它们时的样子:
$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"
https://stackoverflow.com/questions/15767657
复制相似问题