This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: problems with exec("rundll32.exe shell32.dll...")
- From: Ranjit Mathew <rmathew at hotmail dot com>
- To: java-patches at gcc dot gnu dot org
- Cc: java at gcc dot gnu dot org
- Date: Wed, 21 May 2003 23:53:37 +0530
- Subject: Re: problems with exec("rundll32.exe shell32.dll...")
- References: <OF77B11B37.09ABBEB8-ON80256D2C.00500827@cambridge.arm.com> <3ECB6A78.8040907@hotmail.com>
> > 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").
Here's a little patch (against 3.3) that proposes to fix this
(and PR 10880?) - I have tested this out on Win98 so far:
(The "String s = progarray[i]" is a vestigial remanant of a
variant with trim( ) - it turns out that at least JRE 1.4.1_01
does not trim( ) elements and we faithfully try to reproduce
this quirk.)
Index: ChangeLog
from Ranjit Mathew <rmathew@hotmail.com>
* java/lang/Win32Process.java (ConcreteProcess): Surround
a command line element with quotes if it contains an
embedded space or tab.
* java/lang/natWin32Process.cc (startProcess): Do not
surround command line elements with quotes here.
Index: java/lang/Win32Process.java
===================================================================
--- java/lang/Win32Process.java 2003-05-21 22:39:54.000000000 +0530
+++ java/lang/Win32Process.java 2003-05-21 23:01:19.000000000 +0530
@@ -68,4 +68,12 @@
throws IOException
{
+ for (int i = 0; i < progarray.length; i++)
+ {
+ String s = progarray[i];
+
+ if ( (s.indexOf (' ') >= 0) || (s.indexOf ('\t') >= 0))
+ progarray[i] = "\"" + s + "\"";
+ }
+
startProcess (progarray, envp, dir);
}
Index: java/lang/natWin32Process.cc
===================================================================
--- java/lang/natWin32Process.cc 2003-05-21 22:40:04.000000000 +0530
+++ java/lang/natWin32Process.cc 2003-05-21 22:48:34.000000000 +0530
@@ -137,5 +137,5 @@
for (int i = 0; i < progarray->length; ++i)
- cmdLineLen += (_Jv_GetStringUTFLength (elts[i]) + 3);
+ cmdLineLen += (_Jv_GetStringUTFLength (elts[i]) + 1);
char *cmdLine = (char *) _Jv_Malloc (cmdLineLen + 1);
@@ -146,9 +146,7 @@
if (i > 0)
*cmdLineCurPos++ = ' ';
- *cmdLineCurPos++ = '\"';
jsize s = _Jv_GetStringUTFLength (elts[i]);
_Jv_GetStringUTFRegion (elts[i], 0, s, cmdLineCurPos);
cmdLineCurPos += s;
- *cmdLineCurPos++ = '\"';
}
*cmdLineCurPos = '\0';