在后台使用powershell脚本中的参数启动.exe

在后台使用powershell脚本中的参数启动.exe,powershell,jobs,job-scheduling,Powershell,Jobs,Job Scheduling,我有一个程序,在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} -argum

我有一个程序,在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脚本中运行。

该作业将是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"

命名参数版本是什么样子的?我已经在使用$args调用脚本,因此无法使用args数组。您仍然可以使用args。它在scriptblock中有一个新的作用域(它将在另一个powershell.exe实例中用于该作业),但我已更新以显示命名参数。啊,好的。现在我遇到了另一个问题。你可能也知道这个?