user3841808
user3841808

Reputation: 11

Cannot call perl script from Java

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)

Upvotes: 0

Views: 729

Answers (2)

user4241250
user4241250

Reputation: 11

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

Upvotes: 1

Oncaphillis
Oncaphillis

Reputation: 1908

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 ?

Upvotes: 0

Related Questions