I wrote a console application that basically consumes arguments and starts
other command line apps via System.Process. Let's call it XCompile for now.
I wrote a Visual basic add-in that does pretty much the same thing to
XCompile. Let's call it MyAddin.

XCompile collects information to send to vbc.exe. When it comes across any
arguments that are file paths, it wraps them in quotes. For example:

[VB.Net psuedocode (from XCompile)]
Dim prms As String
Dim fil As String
Dim files() As String = New String() {"c:\Documents and Settings\...\file
with spaces.vb", "temp\NoSpaces.vb"}

For Each fil In files
prms &= " "
prms &= """"c
prms &= fil
prms &= """"c
Next

Console.WriteLine("vbc.exe " & Trim(prms))

Dim si As New ProcessStartInfo("vbc.exe", Trim(prms))
si.UseShellExecute = False
si.CreateNoWindow = True
si.RedirectStandardOutput = True
si.RedirectStandardErr = True
Dim prc As Process = Process.Start(si)
...

This works well. The problem I come across is when I try to use a Process
against XCompile in the same fashion. vbvc pretends that all the quotes have
disappeared and treats everything with a space in it as a separate argument.

[VB.Net psuedocode (from MyAddin)]
Dim si As New ProcessStartInfo("XCompile.exe", Trim(prms))
si.UseShellExecute = False
si.CreateNoWindow = True
si.RedirectStandardOutput = True
si.RedirectStandardErr = True
Dim prc As Process = Process.Start(si)
...

[Output from XCompile]
vbc.exe "c:\Documents and Settings\...\file with spaces.vb"
"temp\NoSpaces.vb"
vbc : Command line error BC2001 : file 'and' could not be found
vbc : Command line error BC2001 : file 'Settings\waldo\My' could not be
found
...
vbc : Command line error BC2008 : no input sources specified



So in summary, XCompile works, shelling to vbc by itself, but doesn't work
when MyAddin shells to XCompile.
Any Ideas why this happens/how to fix it?

Thanks in advance.
WALDO

Re: Problem with System.Process and quotes/spaces in arguments by Chris

Chris
Fri Jan 28 09:38:55 CST 2005

You said that XCompile adds quotation marks to any file paths. I
notice also, that your pseudocode is adding quotation marks.

Could there be extra quotation marks in the command string? In other
words, is the command string somehow ending up like the following:

""c:\Documents and Settings\waldo\My ...""
Note the extra quotation marks on the ends.

Just a thought


RE: Problem with System.Process and quotes/spaces in arguments by PIEBALD

PIEBALD
Fri Jan 28 10:01:07 CST 2005

I'm not familar enough with VB to understand some of that code. I'll just say
that I wrote a routine I call "DoubleEscape" (escape by doubling) that I use
in similar situations, passing strings containing quotes around (mostly to
ADO.net).

It turns: They call me "Ishmael".
To: They call me ""Ishmael"".

Which is often needed when I build SQL statements.

You pass in a string to work on and a string containing the characters that
need to be doubled (usually quotes), e.g.

newstring = DoubleEscape ( oldstring , "\"" ) ;

I also have a routine AddEscape that is similar but could make the above
string into:
They call me \"Ishmael\".

The C# code for these is:

public static string
DoubleEscape
(
string subject ,
string problems
)
{
string result = "" ;

for ( int runner = 0 ; runner < subject.Length ; runner++ )
{
if ( problems.IndexOf ( subject [ runner ] , 0 ,
problems.Length ) != -1 )
{
result += subject [ runner ] ;
}

result += subject [ runner ] ;
}

return ( result ) ;
}

public static string
AddEscape
(
string subject ,
string problems ,
char escape
)
{
string result = "" ;

for ( int runner = 0 ; runner < subject.Length ; runner++ )
{
if ( problems.IndexOf ( subject [ runner ] , 0 ,
problems.Length ) != -1 )
{
result += escape ;
}

result += subject [ runner ] ;
}

return ( result ) ;
}



Re: Problem with System.Process and quotes/spaces in arguments by WALDO

WALDO
Fri Jan 28 11:38:09 CST 2005

The pseudocode IS XCompile. Not the pseudocode is adding quotes AND XComile
is adding quotes.

I actually tried doing that on puropse (doubling up on qoutes when not run
from the command line), but it didn't work.

"Chris Dunaway" <dunawayc@gmail.com> wrote in message
news:1106926735.441411.115650@f14g2000cwb.googlegroups.com...
> You said that XCompile adds quotation marks to any file paths. I
> notice also, that your pseudocode is adding quotation marks.
>
> Could there be extra quotation marks in the command string? In other
> words, is the command string somehow ending up like the following:
>
> ""c:\Documents and Settings\waldo\My ...""
> Note the extra quotation marks on the ends.
>
> Just a thought
>



Re: Problem with System.Process and quotes/spaces in arguments by WALDO

WALDO
Fri Jan 28 11:39:35 CST 2005

I tried double escaping my quotes when not running from the command line. no
joy.

"PIEBALD" <PIEBALD@discussions.microsoft.com> wrote in message
news:2C749A6F-4526-4D1E-911E-C10B3C9FEB48@microsoft.com...
> I'm not familar enough with VB to understand some of that code. I'll just
say
> that I wrote a routine I call "DoubleEscape" (escape by doubling) that I
use
> in similar situations, passing strings containing quotes around (mostly to
> ADO.net).
>
> It turns: They call me "Ishmael".
> To: They call me ""Ishmael"".
>
> Which is often needed when I build SQL statements.
>
> You pass in a string to work on and a string containing the characters
that
> need to be doubled (usually quotes), e.g.
>
> newstring = DoubleEscape ( oldstring , "\"" ) ;
>
> I also have a routine AddEscape that is similar but could make the above
> string into:
> They call me \"Ishmael\".
>
> The C# code for these is:
>
> public static string
> DoubleEscape
> (
> string subject ,
> string problems
> )
> {
> string result = "" ;
>
> for ( int runner = 0 ; runner < subject.Length ; runner++ )
> {
> if ( problems.IndexOf ( subject [ runner ] , 0 ,
> problems.Length ) != -1 )
> {
> result += subject [ runner ] ;
> }
>
> result += subject [ runner ] ;
> }
>
> return ( result ) ;
> }
>
> public static string
> AddEscape
> (
> string subject ,
> string problems ,
> char escape
> )
> {
> string result = "" ;
>
> for ( int runner = 0 ; runner < subject.Length ; runner++ )
> {
> if ( problems.IndexOf ( subject [ runner ] , 0 ,
> problems.Length ) != -1 )
> {
> result += escape ;
> }
>
> result += subject [ runner ] ;
> }
>
> return ( result ) ;
> }
>
>



Re: Problem with System.Process and quotes/spaces in arguments by WALDO

WALDO
Fri Jan 28 11:52:40 CST 2005

So I thought, "Try to eliminate the problem." I merged XCompile and MyAddin
into one app and found a whole slew of new problems. Rather than having
MyAddin shell to XCompile and XCompile shell to vbc, MyAddin does all the
work of XCompile (exact same code).

I got the exact same problem. It seems this funky behavior is produced when
it's a NON command-line app (or at least an add-in). Running XCompile by
itself doesn't have a problem. Running MyAddin, whether it shells to
XCompile or does XCompile's work (shelling to vbc), seems to have the same
effect. The question is "Is it because it's an Add-In (something to do with
COM interop, maybe?) or is it because it's non-commandline (WINEXE/LIBRARY
instead of EXE)?"

If I run XCompile, or even MyAddin, from the command-line or double-clicking
it, it compiles successfully using the quotes the exact same.

In addition to that, I've noticed that if you actually run command-line
exe's from the command line instead of double-clicking them,
Console.WriteLine doesn't produce anything. Why is that?

"WALDO" <NOSPAM@NOSPAM.COM> wrote in message
news:%23rNSAhLBFHA.612@TK2MSFTNGP09.phx.gbl...
> I wrote a console application that basically consumes arguments and starts
> other command line apps via System.Process. Let's call it XCompile for
now.
> I wrote a Visual basic add-in that does pretty much the same thing to
> XCompile. Let's call it MyAddin.
>
> XCompile collects information to send to vbc.exe. When it comes across any
> arguments that are file paths, it wraps them in quotes. For example:
>
> [VB.Net psuedocode (from XCompile)]
> Dim prms As String
> Dim fil As String
> Dim files() As String = New String() {"c:\Documents and Settings\...\file
> with spaces.vb", "temp\NoSpaces.vb"}
>
> For Each fil In files
> prms &= " "
> prms &= """"c
> prms &= fil
> prms &= """"c
> Next
>
> Console.WriteLine("vbc.exe " & Trim(prms))
>
> Dim si As New ProcessStartInfo("vbc.exe", Trim(prms))
> si.UseShellExecute = False
> si.CreateNoWindow = True
> si.RedirectStandardOutput = True
> si.RedirectStandardErr = True
> Dim prc As Process = Process.Start(si)
> ...
>
> This works well. The problem I come across is when I try to use a Process
> against XCompile in the same fashion. vbvc pretends that all the quotes
have
> disappeared and treats everything with a space in it as a separate
argument.
>
> [VB.Net psuedocode (from MyAddin)]
> Dim si As New ProcessStartInfo("XCompile.exe", Trim(prms))
> si.UseShellExecute = False
> si.CreateNoWindow = True
> si.RedirectStandardOutput = True
> si.RedirectStandardErr = True
> Dim prc As Process = Process.Start(si)
> ...
>
> [Output from XCompile]
> vbc.exe "c:\Documents and Settings\...\file with spaces.vb"
> "temp\NoSpaces.vb"
> vbc : Command line error BC2001 : file 'and' could not be found
> vbc : Command line error BC2001 : file 'Settings\waldo\My' could not be
> found
> ...
> vbc : Command line error BC2008 : no input sources specified
>
>
>
> So in summary, XCompile works, shelling to vbc by itself, but doesn't work
> when MyAddin shells to XCompile.
> Any Ideas why this happens/how to fix it?
>
> Thanks in advance.
> WALDO
>
>



Re: Problem with System.Process and quotes/spaces in arguments by WALDO

WALDO
Fri Jan 28 13:30:44 CST 2005

My own stupidity prevails sometimes.
I compiled MyAddin as a windows exe which is why I wasn't getting output
from the command line.
I wonder if that solves my vbc problem.

"WALDO" <NOSPAM@NOSPAM.COM> wrote in message
news:uxMhqIWBFHA.3472@TK2MSFTNGP14.phx.gbl...
> So I thought, "Try to eliminate the problem." I merged XCompile and
MyAddin
> into one app and found a whole slew of new problems. Rather than having
> MyAddin shell to XCompile and XCompile shell to vbc, MyAddin does all the
> work of XCompile (exact same code).
>
> I got the exact same problem. It seems this funky behavior is produced
when
> it's a NON command-line app (or at least an add-in). Running XCompile by
> itself doesn't have a problem. Running MyAddin, whether it shells to
> XCompile or does XCompile's work (shelling to vbc), seems to have the same
> effect. The question is "Is it because it's an Add-In (something to do
with
> COM interop, maybe?) or is it because it's non-commandline (WINEXE/LIBRARY
> instead of EXE)?"
>
> If I run XCompile, or even MyAddin, from the command-line or
double-clicking
> it, it compiles successfully using the quotes the exact same.
>
> In addition to that, I've noticed that if you actually run command-line
> exe's from the command line instead of double-clicking them,
> Console.WriteLine doesn't produce anything. Why is that?
>
> "WALDO" <NOSPAM@NOSPAM.COM> wrote in message
> news:%23rNSAhLBFHA.612@TK2MSFTNGP09.phx.gbl...
> > I wrote a console application that basically consumes arguments and
starts
> > other command line apps via System.Process. Let's call it XCompile for
> now.
> > I wrote a Visual basic add-in that does pretty much the same thing to
> > XCompile. Let's call it MyAddin.
> >
> > XCompile collects information to send to vbc.exe. When it comes across
any
> > arguments that are file paths, it wraps them in quotes. For example:
> >
> > [VB.Net psuedocode (from XCompile)]
> > Dim prms As String
> > Dim fil As String
> > Dim files() As String = New String() {"c:\Documents and
Settings\...\file
> > with spaces.vb", "temp\NoSpaces.vb"}
> >
> > For Each fil In files
> > prms &= " "
> > prms &= """"c
> > prms &= fil
> > prms &= """"c
> > Next
> >
> > Console.WriteLine("vbc.exe " & Trim(prms))
> >
> > Dim si As New ProcessStartInfo("vbc.exe", Trim(prms))
> > si.UseShellExecute = False
> > si.CreateNoWindow = True
> > si.RedirectStandardOutput = True
> > si.RedirectStandardErr = True
> > Dim prc As Process = Process.Start(si)
> > ...
> >
> > This works well. The problem I come across is when I try to use a
Process
> > against XCompile in the same fashion. vbvc pretends that all the quotes
> have
> > disappeared and treats everything with a space in it as a separate
> argument.
> >
> > [VB.Net psuedocode (from MyAddin)]
> > Dim si As New ProcessStartInfo("XCompile.exe", Trim(prms))
> > si.UseShellExecute = False
> > si.CreateNoWindow = True
> > si.RedirectStandardOutput = True
> > si.RedirectStandardErr = True
> > Dim prc As Process = Process.Start(si)
> > ...
> >
> > [Output from XCompile]
> > vbc.exe "c:\Documents and Settings\...\file with spaces.vb"
> > "temp\NoSpaces.vb"
> > vbc : Command line error BC2001 : file 'and' could not be found
> > vbc : Command line error BC2001 : file 'Settings\waldo\My' could not be
> > found
> > ...
> > vbc : Command line error BC2008 : no input sources specified
> >
> >
> >
> > So in summary, XCompile works, shelling to vbc by itself, but doesn't
work
> > when MyAddin shells to XCompile.
> > Any Ideas why this happens/how to fix it?
> >
> > Thanks in advance.
> > WALDO
> >
> >
>
>



Re: Problem with System.Process and quotes/spaces in arguments by WALDO

WALDO
Fri Jan 28 13:34:47 CST 2005

I'll be damned. It solved my problem

:|

"WALDO" <NOSPAM@NOSPAM.COM> wrote in message
news:uMAod$WBFHA.3236@TK2MSFTNGP15.phx.gbl...
> My own stupidity prevails sometimes.
> I compiled MyAddin as a windows exe which is why I wasn't getting output
> from the command line.
> I wonder if that solves my vbc problem.
>
> "WALDO" <NOSPAM@NOSPAM.COM> wrote in message
> news:uxMhqIWBFHA.3472@TK2MSFTNGP14.phx.gbl...
> > So I thought, "Try to eliminate the problem." I merged XCompile and
> MyAddin
> > into one app and found a whole slew of new problems. Rather than having
> > MyAddin shell to XCompile and XCompile shell to vbc, MyAddin does all
the
> > work of XCompile (exact same code).
> >
> > I got the exact same problem. It seems this funky behavior is produced
> when
> > it's a NON command-line app (or at least an add-in). Running XCompile by
> > itself doesn't have a problem. Running MyAddin, whether it shells to
> > XCompile or does XCompile's work (shelling to vbc), seems to have the
same
> > effect. The question is "Is it because it's an Add-In (something to do
> with
> > COM interop, maybe?) or is it because it's non-commandline
(WINEXE/LIBRARY
> > instead of EXE)?"
> >
> > If I run XCompile, or even MyAddin, from the command-line or
> double-clicking
> > it, it compiles successfully using the quotes the exact same.
> >
> > In addition to that, I've noticed that if you actually run command-line
> > exe's from the command line instead of double-clicking them,
> > Console.WriteLine doesn't produce anything. Why is that?
> >
> > "WALDO" <NOSPAM@NOSPAM.COM> wrote in message
> > news:%23rNSAhLBFHA.612@TK2MSFTNGP09.phx.gbl...
> > > I wrote a console application that basically consumes arguments and
> starts
> > > other command line apps via System.Process. Let's call it XCompile for
> > now.
> > > I wrote a Visual basic add-in that does pretty much the same thing to
> > > XCompile. Let's call it MyAddin.
> > >
> > > XCompile collects information to send to vbc.exe. When it comes across
> any
> > > arguments that are file paths, it wraps them in quotes. For example:
> > >
> > > [VB.Net psuedocode (from XCompile)]
> > > Dim prms As String
> > > Dim fil As String
> > > Dim files() As String = New String() {"c:\Documents and
> Settings\...\file
> > > with spaces.vb", "temp\NoSpaces.vb"}
> > >
> > > For Each fil In files
> > > prms &= " "
> > > prms &= """"c
> > > prms &= fil
> > > prms &= """"c
> > > Next
> > >
> > > Console.WriteLine("vbc.exe " & Trim(prms))
> > >
> > > Dim si As New ProcessStartInfo("vbc.exe", Trim(prms))
> > > si.UseShellExecute = False
> > > si.CreateNoWindow = True
> > > si.RedirectStandardOutput = True
> > > si.RedirectStandardErr = True
> > > Dim prc As Process = Process.Start(si)
> > > ...
> > >
> > > This works well. The problem I come across is when I try to use a
> Process
> > > against XCompile in the same fashion. vbvc pretends that all the
quotes
> > have
> > > disappeared and treats everything with a space in it as a separate
> > argument.
> > >
> > > [VB.Net psuedocode (from MyAddin)]
> > > Dim si As New ProcessStartInfo("XCompile.exe", Trim(prms))
> > > si.UseShellExecute = False
> > > si.CreateNoWindow = True
> > > si.RedirectStandardOutput = True
> > > si.RedirectStandardErr = True
> > > Dim prc As Process = Process.Start(si)
> > > ...
> > >
> > > [Output from XCompile]
> > > vbc.exe "c:\Documents and Settings\...\file with spaces.vb"
> > > "temp\NoSpaces.vb"
> > > vbc : Command line error BC2001 : file 'and' could not be found
> > > vbc : Command line error BC2001 : file 'Settings\waldo\My' could not
be
> > > found
> > > ...
> > > vbc : Command line error BC2008 : no input sources specified
> > >
> > >
> > >
> > > So in summary, XCompile works, shelling to vbc by itself, but doesn't
> work
> > > when MyAddin shells to XCompile.
> > > Any Ideas why this happens/how to fix it?
> > >
> > > Thanks in advance.
> > > WALDO
> > >
> > >
> >
> >
>
>