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

Ranjit Mathew rmathew@hotmail.com
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
> http://java.sun.com/j2se/1.4.1/docs/api/java/util/StringTokenizer.html )

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 (natWin32Process.cc) and modify the
Java code (Win32Process.java) 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.

-- 
Ranjit Mathew          Email: rmathew AT hotmail DOT com

Bangalore, INDIA.      Web: http://ranjitmathew.tripod.com/
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: First.java
URL: <http://gcc.gnu.org/pipermail/java/attachments/20030521/bab980b7/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: t.c
URL: <http://gcc.gnu.org/pipermail/java/attachments/20030521/bab980b7/attachment.c>


More information about the Java mailing list