Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Passing Empty Strings To External Commands?

Closed Thread
 
Thread Tools Display Modes
Old 05-13-2007   #1 (permalink)
Richard J Cox
Guest


 

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
Old 05-14-2007   #2 (permalink)
Keith Hill
Guest


 

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

Old 05-14-2007   #3 (permalink)
Oisin Grehan
Guest


 

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

Old 05-14-2007   #4 (permalink)
Oisin Grehan
Guest


 

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

Old 05-15-2007   #5 (permalink)
Richard J Cox
Guest


 

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...

Old 05-15-2007   #6 (permalink)
Keith Hill [MVP]
Guest


 

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


Old 05-15-2007   #7 (permalink)
Oisin Grehan
Guest


 

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

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Out-Default and external commands Tomas Restrepo [MVP] PowerShell 2 03-17-2008 12:34 PM
Powershell passing $null to .Net assembly is cast to String.Empty Mel PowerShell 5 02-12-2008 05:42 AM
No error from external commands when called from synthetic method Catweazle PowerShell 3 12-13-2007 02:09 PM
passing parameters to an external program using PowerShell variables freddy chavez PowerShell 3 07-25-2007 05:23 PM
passing params to windows commands Koko PowerShell 5 04-20-2007 07:26 AM








Vistax64.com 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 2005-2008

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 47 48 49 50