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

Andrew.Ferguson@arm.com Andrew.Ferguson@arm.com
Tue May 20 13:03:00 GMT 2003


hi,

 thanks but this hasn't worked either - in fact passing any file as the
arg[0] makes no difference(!), I don't think its even getting that far
(altered the code to as below)

I don't understand exactly how this could be going wrong, unless maybe "_"
is somehow munged by Runtime.exec?

thanks,
asjf

import java.io.*;
import java.util.*;

public class GCJTest {
      public static void main(String [] arg) throws Exception {
            String filename = new File(arg[0]).getAbsolutePath();

            // can't use 1.4 String.replaceAll
            //filename = filename.replaceAll("\\\\","\\\\\\\\"); // replace
\ with \\

            String result = "", tok ="";
            for(StringTokenizer st = new
StringTokenizer(filename,"\\",true); st.hasMoreTokens(); )
                  result+= (tok= st.nextToken()).equals("\\") ? "\\\\" :
tok;

            System.out.println(filename+" to "+result);

            Runtime.getRuntime().exec("rundll32.exe shell32.dll
ShellExec_RunDLL "+result);
      }
}


>I just ran into some Runtime.exec() problems as well.
>
>See PR 10880 that I reported.
>
>There is something funny going on with '\'s.
>
>My kludge was to search & replace a single backslash with two
>backslashes in the argument to Runtime.exec().
>
>This kludge takes advantage of that Windows interprets
>c:\temp and c:\\temp as the same path in certain cases, so
>my code now works with JRE and GCJ.
>
>
>Øyvind





More information about the Java mailing list