![](/img/trans.png)
[英]How to pass a string variable to a PowerShell function from python
[英]Trying to pass a string back from a function in PowerShell
function ExtractLocations([ref]$lp_Locations) {
$lp_Locations.Value = "A STRING VALUE"
return 0
}
...
$Locations = ""
if (@(ExtractLocations([ref]$Locations)) -ne 0) {
RecordErrorThenExit
}
$Locations
总是以空白字符串结尾。
除了@ mklemen0所说的那样,要设置值,您无需像$Variable.Value = 'Something'
,它只是$Variable = 'Something'
使用@()
表达式,可以将输出转换为此处不需要的数组。 在PowerShell中不建议声明类似于c#中的方法的函数。 您可以像下面这样。
function ExtractLocations{
Param([ref]$lp_Locations)
$lp_Locations = "A STRING VALUE"
return 0
}
ExtractLocations -lp_Locations ([ref]$Locations)
无论我如何尝试都无法使它与参数一起使用,因此将值作为字符串返回,并且可以正常工作:
函数ExtractLocations {.... return $ lp_Locations}
$ Locations = ExtractLocations写入“修改$ TABLE以重新安排位置=($($ Locations.value))\\ p \\ g” | sql $ SQLFLAGS $ TARGETDB
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.