繁体   English   中英

无法将启动过程与启动作业一起使用

[英]Unable to use start-process with start-job

我试图通过启动过程执行安装,但是我希望它作为一项工作执行,因此我可以执行其他一些语句,同时还可以在后台运行时检查安装状态。

这是我要执行的部分代码-

$SetupPath = "C:\Test Installs"
# Enclose the path to setup.exe in quotes
$Setup = "`"" + "$SetupPath\setup.exe" + "`""

$command = "{$SetupProcess=" + "Start-process" + " " + `
"$Setup" + " "+ "-ArgumentList" + " " + `
"/config   config.xml" + " " + "-Wait -PassThru" + "}"

# The above command equals-> {$SetupProcess=Start-process "C:\Test Installs\setup.exe" -ArgumentList /config   config.xml -Wait -PassThru}

#Change string to Scriptblock
$ScriptBlock = [Scriptblock]::Create($command) 

$job1 = Start-Job -ScriptBlock $ScriptBlock -Name "SetupJob"

当我运行此命令并尝试通过Receieve-Job取回结果时,我仅取回我通过脚本块传递的命令字符串。 似乎开始过程命令未执行。 有什么我想念的吗?

摆脱$ command定义中的{} [ScriptBlock] :: Create()需要一些文本,并将包装在脚本块中。 您还可以简化此操作:

$SetupPath = "C:\Test Installs"
# Enclose the path to setup.exe in quotes
$Setup = "`"$SetupPath\setup.exe`""

$command = "SetupProcess = Start-process `"$Setup`" -ArgumentList `"/config config.xml`" -Wait -PassThru"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM