可變我有一個shell腳本應該在後臺啓動一個.exe文件:解釋在PowerShell中{}腳本塊
$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"
?
在$ block中變量$ strPath是空的,因爲scriptblock是一個全新的腳本。你的腳本塊需要接受參數。噢,[不要使用匈牙利語](http://windowsitpro.com/blog/what-do-not-do-powershell-part-5)。不是一個大問題,但實踐使得完美。 –