ndp
ndp

Reputation: 893

ProcessBuilder can't find perl

I'm trying to execute a perl script from java with the following code:

    ProcessBuilder script =
    new ProcessBuilder("/opt/alert-ssdb.pl");
    Process tmp =  script.start();

But when I execute it it returns

 java.io.IOException: Cannot run program "/opt/alert-ssdb.pl": java.io.IOException: error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:488)
at scripttest.main(scripttest.java:11)
Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.<init>(UNIXProcess.java:164)
at java.lang.ProcessImpl.start(ProcessImpl.java:81)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:470)
... 1 more

about the file

ls -l alert-ssdb.pl
-rwxr-xr-x. 1 root root alert-ssdb.pl

I tried running /usr/bin/perl/ with the script as an argument and it also failed with the same exception.

/bin/ls and other simple commands run without a problem though. Also the first line of the script is #!/usr/bin/perl and when run on command line it works

what am I missing?

//Update: The big picture is that I'm trying to call the script via a storm bolt and it fails at that point. I managed to make it work by defining a python script as a bolt using

 super(python,myscript.py)

(myscript imports the storm library) and from myscript I call the perl script. I haven't tried yet but I suppose that If I modify the perl script to be a storm bolt it will run nicely.

Upvotes: 0

Views: 1507

Answers (1)

MDrabic
MDrabic

Reputation: 917

Try changing

    new ProcessBuilder("/opt/alert-ssdb.pl");

to:

    new ProcessBuilder("/usr/bin/perl", "/opt/alert-ssdb.pl");

I've had past experiences where not all my environment variables from the shell exist when using ProcessBuilder.

Edited to reflect @dcsohl's comment.

Upvotes: 1

Related Questions