本文介绍了使用powershell将空参数传递给可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Powershell在传递到命令时似乎丢弃了空字符串参数。我有这个代码
Powershell seems to drop empty string arguments when passed to a command. I have this code
PS D:\> $b.name = "foo bar"
PS D:\> ./echoargs $b.name
Arg 0 is D:\echoargs.exe
Arg 1 is foo bar
PS D:\> $b.name = ""
PS D:\> ./echoargs $b.name
Arg 0 is D:\echoargs.exe
你可以假设$ b有一个'name'成员。我怎么能将这作为参数传递给exe,即使值是一个空字符串。我尝试使用调用运算符没有成功。
You can assume that $b has a 'name' member. How can i pass this as an argument to the exe even when the value is an empty string. I've tried using the call operator with no success.
推荐答案
如果你想要一个空字符串,参数如下:
If you want an empty string to appear try escaped quotes around the argument like so:
PS> $b = [psobject]@{name = ''}
PS> echoargs `"$($b.Name)`"
Arg 0 is <>
Command line:
"C:\Users\Keith\Pscx\Trunk\Src\Pscx\bin\Release\Apps\EchoArgs.exe" ""
注意,我在V3上测试了这个,所以我不知道行为是否会在V2上完全相同。
Note that I tested this on V3 so I'm not sure if the behavior will be exactly the same on V2.
这篇关于使用powershell将空参数传递给可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!