Hi Jason,
Can you try this:
cscript /Nologo print-args.vbs foo '""' bar
- or -
cscript /Nologo print-args.vbs foo ([string]::empty) bar
---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar:
http://tinyurl.com/PSToolbar
JC> I'm using a program that takes as one of its parameters a string
JC> that will be appended to the output. One possible option for this
JC> parameter is the empty string. I can pass the empty string from a
JC> cmd.exe shell with "".
JC>
JC> For example, consider the Visual Basic script, named print-args.vbs:
JC> WScript.echo WScript.Arguments.Item(0)
JC> WScript.echo WScript.Arguments.Item(1)
JC> WScript.echo Wscript.Arguments.Item(2)
JC> If this script is executed using the following syntax:
JC>
JC> PS C:\> cmd /c 'cscript /Nologo print-args.vbs foo "" bar'
JC>
JC> foo
JC>
JC> bar
JC>
JC> But if the same script is run from the Powershell, the parameter is
JC> missing.
JC>
JC> PS C:\> cscript /Nologo print-args.vbs foo "" bar
JC> foo
JC> bar
JC> C:\print-args.vbs(3, 1) Microsoft VBScript runtime error: Subscript
JC> out of
JC> range
JC> After some muddling around with the syntax, I found that I could in
JC> fact force Powershell to pass the empty string using the following
JC> syntax.
JC>
JC> PS C:\> cscript /Nologo print-args.vbs foo `"`" bar foo
JC>
JC> bar
JC>
JC> So for my question.
JC>
JC> Is the `"`" the recommended syntax for passing an empty-string
JC> parameter?
JC>
JC> I find the syntax confusing... and in the case of my application,
JC> when I use the "" syntax that works in cmd.exe and other common
JC> shells (i.e. bash), it's silently ignored by Powershell, so the
JC> subsequent parameter gets consumed where I intended to have an empty
JC> string. This causes very bad unintended behavior.
JC>
JC> I acknowledge that Powershell isn't cmd.exe or bash, but I have
JC> another question. Is there a reason that "" or '' couldn't be
JC> honored as the empty string when passed to a child command? If the
JC> answer is no, I'll follow up with a ticket on MS Connect.
JC>
JC> Regards,
JC> Jason