我有一个程序,通常在powershell中这样启动:
I have a programm which i usually start like this in powershell:
.\storage\bin\storage.exe -f storage\conf\storage.conf在后台调用它的正确语法是什么?我尝试了很多组合,例如:
What is the correct syntax for calling it in the background? I tried many combinations like:
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脚本中运行.
but without success. Also it should run in a powershell script.
推荐答案该作业将是PowerShell.exe的另一个实例,并且不会在同一路径下启动,因此.无法正常工作.它需要知道storage.exe在哪里.
The job will be another instance of PowerShell.exe and it will not start in same path so . won't work. It needs to know where storage.exe is.
此外,您还必须使用脚本块中自变量列表中的自变量.您可以使用内置的args数组,也可以使用命名参数. args方式需要最少的代码.
Also you have to use the arguments from argumentlist in the scriptblock. You can either use the built-in args array or do named parameters. The args way needs the least amount of code.
$block = {& "C:\full\path\to\storage\bin\storage.exe" $args} start-job -scriptblock $block -argumentlist "-f", "C:\full\path\to\storage\conf\storage.conf"命名参数有助于了解应该使用什么参数.使用它们的样子如下:
Named parameters are helpful to know what what arguments are supposed to be. Here's how it would look using them:
$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"更多推荐
在Powershell脚本中使用参数在后台启动.exe
发布评论