當您想在PowerShell中的字符串中使用變量時,您有不同的選項。首先,如果需要字符串中的變量,您將始終需要使用"
而不是'
來包裝字符串。
$myVariable = "MyPropertyValue"
Write-Host "The variable has the value $MyVariable"
上面的代碼將產生的輸出:如果要使用的變量的屬性(或任何表達式),其插入到串
The variable has the value MyPropertyValue
,需要包裝在帶有$(expression goes here)
的字符串,例如
$MyVariable = New-Object PSObject -Property @{ MyPropertyName = 'MyPropertyValue' }
# The following will fail getting the property since it will only consider
# the variable name as code, not the dot or the property name. It will
# therefore ToString the object and append the literal string .MyPropertyName
Write-Host "Failed property value retrieval: $MyVariable.MyPropertyName"
# This will succeed, since it's wrapped as code.
Write-Host "Successful property value retrieval: $($MyVariable.MyPropertyName)"
# You can have any code in those wrappers, for example math.
Write-Host "Maths calculating: 3 * 27 = $(3 * 27)"
上面的代碼會產生以下輸出:
Failed property value retrieval: @{MyPropertyName=MyPropertyValue}.MyPropertyName
Successful property value retrieval: MyPropertyValue
Maths calculating: 3 * 27 = 81
我一般儘量當我在PowerShell中啓動進程,因爲它給了我更多的控制權的過程中可能使用的Start-Process
cmdlet的開始。這意味着您可以使用類似於以下內容的內容。
Get-ChildItem "C:\forms\fortest" -Filter "*.fmb" -recurse | Foreach {
$FormPath = $_.FullName
$ResultingFileName = $_.BaseName
Start-Process -FilePath "C:\Oracle\Middleware\Oracle_FRHome1\BIN\frmcmp.exe" -ArgumentList "module=$FormPath", "userid=xyz/[email protected]", "Output_File=C:\forms\11\common\fmx\$ResultingFileName.fmx"
}
您也可以在-Wait
參數添加到開始處理命令,如果你想與下一個項目的編制要等到當前編譯完成。
你是什麼意思的「不工作」?錯誤信息?沒有結果?完全不同的東西? – vonPryz
其不工作意味着: - 沒有結果 – p27