Java CreateProcess error=193, %1 is not a valid Win32 application

19,207

Solution 1

There a few possible causes for the "%1 is not a valid Win32 application" message including:

  • the pathname for the application is incorrect,
  • the file named by the pathname is not recognized by Windows as an executable, or
  • the file is a 32 bit executable, but for some reason it is trying to load a 64 bit DLL.

In this case, you are using a relative pathname for the executable, so it is possible that the JVM's current directory is different to what you think ... and the optimizer file is not in that directory.

Try the following:

  1. Replace "./optimizer" with an absolute pathname.

  2. It the command (absolute) pathname or the sourceFile arguments contain spaces, replace the command string with an array of strings; e.g.

    exec(new String[]{
           "C:/path/to/optimizer",
           sourceFile, sourceFile + "a", "--all", "-i"});
    
  3. Try running the command from the command prompt. The idea is to check that this isn't caused by a non-executable file or a DLL problem.

Solution 2

Most likely, your code is not running in the directory you think it is.

Use the OP's code given here: how to get current directory in java?

File directory = new File (".");
try {
    System.out.println ("Current directory's canonical path: " 
            + directory.getCanonicalPath()); 
    System.out.println ("Current directory's absolute  path: " 
                + directory.getAbsolutePath());
}catch(Exception e) {
    System.out.println("Exceptione is ="+e.getMessage());
}

Now compare that to where optimizer is located.

Generally speaking, unless you control how the JVM is invoked, you can't rely on relative paths.

Share:
19,207
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin about 2 years

    I am Trying to read and write Extensible Linking Format (ELF) Below is the Line that I am getting Error.

    p =  r.exec("./optimizer " + sourceFile + " " + sourceFile + "a" + " " + "--all -i");
    

    After Running this line I am Getting Error Like :

    java.io.IOException: Cannot run program "./optimizer": CreateProcess             
    error=193, %1 is not a valid Win32 application
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at java.lang.Runtime.exec(Runtime.java:620)
    at java.lang.Runtime.exec(Runtime.java:450)
    at java.lang.Runtime.exec(Runtime.java:347)
    at GUIMode.GUIMode.actionPerformed(GUIMode.java:213)