当您想在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