problems with exec("rundll32.exe shell32.dll...")

Ranjit Mathew
Wed May 21 14:50:00 GMT 2003

> I think the two marked lines need to be made conditional on elts[i]
> containing whitespace? (whitespace in this case is any of \t, \n, \r, \f -
> this is taken from the parameterless constructor of StringTokenizer
> )

I did a little experiment with trying to get the
*actual* command line passed to a program by Sun's JRE's
Runtime.exec( ) using the Win32 GetCommandLine( ) function
rather than the C runtime's argv array and it more or
less confirms your hypothesis:

   The elements of the command line array are quoted *only if*
   there's a space or a tab (\n, \r and \f are *not* "escaped").

(The MSVC runtime library seems to do its own command
line quotes processing that initially threw me off track.)

> I'd try to send a fix for this but don't know C++ :(

One simple way to do this would be to remove the auto-quoting
bits from the C++ file ( and modify the
Java code ( something like this:

   public ConcreteProcess (String[] progarray,
                           String[] envp,
                           File dir)
     throws IOException
     for (int i = 0; i < progarray.length; i++)
       if ((progarray[i].indexOf (' ') >= 0)
         || (progarray[i].indexOf ('\t') >= 0))
           progarray[i] = "\"" + progarray[i] + "\"";

     startProcess (progarray, envp, dir);

That shouldn't require too much of C++ skills, should it now? ;-)

BTW, I'm attaching a small Java program and a small C
program (for Win32) that demonstrates this distinction
that Sun's JRE makes.


Ranjit Mathew          Email: rmathew AT hotmail DOT com

Bangalore, INDIA.      Web:
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
URL: <>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: t.c
URL: <>

More information about the Java mailing list