我有一个 shell 脚本,它应该在后台启动 .exe:
$strPath = get-location
$block = {& $strPath"\storage\bin\storage.exe" $args}
start-job -scriptblock $block -argumentlist "-f", $strPath"\storage\conf\storage.conf"
在前面的Question https://stackoverflow.com/questions/15767657/start-a-exe-in-the-background-with-parameters-in-a-powershell-script我发现我需要绝对路径。但是,如果您查看以下命令,则不会解释 $strPath 变量:
PS Q:\mles\etl-i_test> .\iprog.ps1 --start1
Start Storage
Id Name State HasMoreData Location Command
-- ---- ----- ----------- -------- -------
37 Job37 Running True localhost & $strPath"\storage\bi...
我怎样才能解决这个问题?
编辑:我知道我需要将路径作为参数传递,如何传递?就像是:
$block = {& $args[0]"\storage\bin\storage.exe" $args[1] $args[2]}
start-job -scriptblock $block -argumentlist $strPath, "-f", $strPath"\storage\conf\storage.conf"
?
脚本块的内容将在 PowerShell.exe 的另一个实例(作为作业)中执行,该实例无法访问您的变量。这就是为什么您需要将它们发送到Start-Job
参数列表。发送作业运行所需的所有数据作为参数。例如 storage.exe 的完整路径,例如
$path = (Get-Location).Path
$block = {& $args[0] $args[1] $args[2]}
start-job -scriptblock $block -argumentlist `
"$path\storage\bin\storage.exe" `
"-f", `
"$path\storage\conf\storage.conf"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)