0

When I'm trying to run a perl script from my main java application:

            try {
                ProcessBuilder pb = new ProcessBuilder(path+"\\script.pl");
                Process p = pb.start();     // Start the process.
                p.waitFor();                // Wait for the process to finish.
                System.out.println("Script executed successfully");
              } catch (Exception e) {
                e.printStackTrace();
                }

            }

I get the following error (not a valid win32 app):

java.io.IOException: Cannot run program "C:\workspace\kepler\Alert_Handler\target\test-classes\script.pl": CreateProcess error=193, %1 no es una aplicación Win32 válida at java.lang.ProcessBuilder.start(Unknown Source)

3
  • possible duplicate of Using Runtime.getRuntime().exec() to run perl code in java Commented Nov 11, 2014 at 19:53
  • does the perl script work when you invoke it manually? Commented Nov 11, 2014 at 19:55
  • No mention of PATHEXT in that "duplicate" Commented Nov 13, 2014 at 0:52

2 Answers 2

1

Unix uses the shebang line to indicate a file is executable, but Windows uses a different mechanism based on file extensions. The file extensions Windows considers executable are those enumerated by the PATHEXT environment variable. You can solve your program by altering your PATHEXT variable as detailed here.

Alternatively, you could explicitly specify you want to launch the script using perl.

new ProcessBuilder("perl.exe", path+"\\script.pl");

- ikegami

Sign up to request clarification or add additional context in comments.

Comments

0

Ok -- my mother-tongue isn't spanish but this

no es una aplicación Win32 válida

Seems to translate into "this isn't a valid Win32 application" so it seems under Windows you explicitly have to start the Perl interpreter with the script as an arg. Something like:

new ProcessBuilder("perl.exe",path+"\\script.pl");

may be ?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.