我有一个外壳脚本,它应该在后台启动一个.exe:
$strPath = get-location
$block = {& $strPath"\storage\bin\storage.exe" $args}
start-job -scriptblock $block -argumentlist "-f", $strPath"\storage\conf\storage.conf"
在前面的Question中,我发现我需要绝对路径。但是,如果您查看该命令,则不会解释$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"
发布于 2013-04-03 00:33:20
脚本块的内容将在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"
https://stackoverflow.com/questions/15769126
复制相似问题