Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Passing Empty Strings To External Commands?

Reply
 
Old 05-13-2007   #1 (permalink)
Richard J Cox


 
 

Passing Empty Strings To External Commands?


In cmd.exe, doing:

ExternalCommand.exe " "

will pass a single argument consisting a a single space to
ExternalCommand.

However doing the same in PSH appears to pass nothing (based on the
content of the arguments array passed to Main in a test .NET console
program).

Spaces in the quotes are preserved if there is a non-space character
(e.g. " . " is passed through including the spaces).

How can I pass a an argument of just spaces?

--
Richard

My System SpecsSystem Spec
Old 05-14-2007   #2 (permalink)
Keith Hill


 
 

Re: Passing Empty Strings To External Commands?

"Richard J Cox" <richard@rjcox.co.uk> wrote in message
news:memo.20070513132446.4148A@rjcox.compulink.co.uk...
>
> In cmd.exe, doing:
>
> ExternalCommand.exe " "
>
> will pass a single argument consisting a a single space to
> ExternalCommand.
>
> However doing the same in PSH appears to pass nothing (based on the
> content of the arguments array passed to Main in a test .NET console
> program).
>
> Spaces in the quotes are preserved if there is a non-space character
> (e.g. " . " is passed through including the spaces).
>
> How can I pass a an argument of just spaces?


I can verify this issue but I'm not coming up with a solution. :-(

--
Keith

My System SpecsSystem Spec
Old 05-14-2007   #3 (permalink)
Oisin Grehan


 
 

Re: Passing Empty Strings To External Commands?

On May 14, 12:14 pm, "Keith Hill" <r_keith_h...@mailhot.nospamIdotcom>
wrote:
> "Richard J Cox" <rich...@rjcox.co.uk> wrote in messagenews:memo.20070513132446.4148A@rjcox.compulink.co.uk...
>
>
>
>
>
>
>
> > In cmd.exe, doing:

>
> > ExternalCommand.exe " "

>
> > will pass a single argument consisting a a single space to
> > ExternalCommand.

>
> > However doing the same in PSH appears to pass nothing (based on the
> > content of the arguments array passed to Main in a test .NET console
> > program).

>
> > Spaces in the quotes are preserved if there is a non-space character
> > (e.g. " . " is passed through including the spaces).

>
> > How can I pass a an argument of just spaces?

>
> I can verify this issue but I'm not coming up with a solution. :-(
>
> --
> Keith- Hide quoted text -
>
> - Show quoted text -


prog.exe "`" `"" (that's quote, backtick, quote, space, backtick,
quote, quote

- Oisin

My System SpecsSystem Spec
Old 05-14-2007   #4 (permalink)
Oisin Grehan


 
 

Re: Passing Empty Strings To External Commands?

On May 14, 2:56 pm, Oisin Grehan <ois...@gmail.com> wrote:
> On May 14, 12:14 pm, "Keith Hill" <r_keith_h...@mailhot.nospamIdotcom>
> wrote:
>
>
>
>
>
> > "Richard J Cox" <rich...@rjcox.co.uk> wrote in messagenews:memo.20070513132446.4148A@rjcox.compulink.co.uk...

>
> > > In cmd.exe, doing:

>
> > > ExternalCommand.exe " "

>
> > > will pass a single argument consisting a a single space to
> > > ExternalCommand.

>
> > > However doing the same in PSH appears to pass nothing (based on the
> > > content of the arguments array passed to Main in a test .NET console
> > > program).

>
> > > Spaces in the quotes are preserved if there is a non-space character
> > > (e.g. " . " is passed through including the spaces).

>
> > > How can I pass a an argument of just spaces?

>
> > I can verify this issue but I'm not coming up with a solution. :-(

>
> > --
> > Keith- Hide quoted text -

>
> > - Show quoted text -

>
> prog.exe "`" `"" (that's quote, backtick, quote, space, backtick,
> quote, quote
>
> - Oisin- Hide quoted text -
>
> - Show quoted text -


hmm, I've overcomplicated that it seems -- you can get away with just
escaping the quotes; e.g. backtick, quote, space, backtick, quote.

- Oisin

My System SpecsSystem Spec
Old 05-15-2007   #5 (permalink)
Richard J Cox


 
 

Re: Passing Empty Strings To External Commands?

In article <1179169017.663546.38260@l77g2000hsb.googlegroups.com>,
oising@gmail.com (Oisin Grehan) wrote:
> On May 14, 12:14 pm, "Keith Hill" <r_keith_h...@mailhot.nospamIdotcom>
> wrote:
> > "Richard J Cox" <rich...@rjcox.co.uk> wrote in
> > > messagenews:memo.20070513132446.4148A@rjcox.compulink.co.uk...

> >
> > > In cmd.exe, doing:

> >
> > > ExternalCommand.exe " "

> >
> > > will pass a single argument consisting a a single space to
> > > ExternalCommand.

> >
> > > However doing the same in PSH appears to pass nothing (based on
> > > the
> > > content of the arguments array passed to Main in a test .NET
> > > console
> > > program).

> >
> > > Spaces in the quotes are preserved if there is a non-space
> > > character
> > > (e.g. " . " is passed through including the spaces).

> >
> > > How can I pass a an argument of just spaces?

> >
> > I can verify this issue but I'm not coming up with a solution. :-(
> >
> > --
> > Keith- Hide quoted text -
> >
> > - Show quoted text -

>
> prog.exe "`" `"" (that's quote, backtick, quote, space, backtick,
> quote, quote



Which does indeed work... and is both (1) obfuscated[1] and (2) an
unreasonable approach because " " works with CmdLets.

Defect raised:
https://connect.microsoft.com/feedba...dbackID=277254
&SiteID=99


--
Richard

[1] I'm not sure how well a PowerShell obfuscated code competition would
work...

My System SpecsSystem Spec
Old 05-15-2007   #6 (permalink)
Keith Hill [MVP]


 
 

Re: Passing Empty Strings To External Commands?

"Richard J Cox" <richard_cox@newsgroup.nospam> wrote in message >
> Defect raised:
> https://connect.microsoft.com/feedba...dbackID=277254
> &SiteID=99


Richard, don't forget that you get to vote on your own defect submissions.
:-)

--
Keith


My System SpecsSystem Spec
Old 05-15-2007   #7 (permalink)
Oisin Grehan


 
 

Re: Passing Empty Strings To External Commands?

On May 15, 4:46 pm, "Keith Hill [MVP]"
<r_keith_h...@no.spam.thank.u.hotmail.com> wrote:
> "Richard J Cox" <richard_...@newsgroup.nospam> wrote in message >
>
> > Defect raised:
> >https://connect.microsoft.com/feedba...x?FeedbackID=2...
> > &SiteID=99

>
> Richard, don't forget that you get to vote on your own defect submissions.
> :-)
>
> --
> Keith


not sure if you saw my second post -- you can get away with a simpler
escape of just the quotes:

prog.exe `" `"

but I agree, it should be the same experience as with cmdlets. I'll
vote for this one.

- Oisin

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Add strings of a csv-file to commands? PowerShell
Passing arguments to external command through PS PowerShell
Out-Default and external commands PowerShell
Powershell passing $null to .Net assembly is cast to String.Empty PowerShell
passing params to windows commands PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46