Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Calling Perl with arguments From Java

by rgwest61 (Initiate)
on May 31, 2016 at 20:18 UTC ( [id://1164639]=note: print w/replies, xml ) Need Help??


in reply to Re: Calling Perl with arguments From Java
in thread Calling Perl with arguments From Java

Hauke D I have tried the following two ways of calling a simple Perl script that currently just prints out the fact that it has been reached from a Java Application. Both attempts were found from an internet search and have not been successful - the expected output is not observed in the Linux window that starts the Java application. Just a little background - the Java code and simple Perl script were developed using the Eclipse IDE and the Perl script resides within one of the previously existing Java packages (Utils)

// First Method List<String> cmds = new ArrayList<String>(); cmds.add("perl"); cmds.add("/home/rwest/workspace/src/AppMaint/Utils/PerlUtil.pl"); ProcessBuilder pb = new ProcessBuilder(cmds); pb.start(); // Second method Process p = RunTime.getRuntime().exec("perl /home/rwest/workspace/src/ +AppMaint/Utils/PerlUtil.pl"); p.waitFor();

Other things I have done in an attempt to get either method to work: 1) Changed the group (chgrp) and access rights (chmod) so that the Perl script exists in the same group as the Java application and has read and execute permission. 2)Added /home/rwest/workspace/src/AppMaint/Utils/PerlUtil.pl to the Eclipse manifest file classpath line. 3) Executed the Perl script from Eclipse IDE with success. 4) Stepped through Eclipse debugger to make sure the applicable Java application lines of code to execute the Perl script are executed.

Replies are listed 'Best First'.
Re^3: Calling Perl with arguments From Java
by haukex (Archbishop) on Jun 01, 2016 at 08:40 UTC

    Hi rgwest61,

    the expected output is not observed in the Linux window that starts the Java application

    That's normal; I suggest you study the documentation of ProcessBuilder:

    By default, the subprocess writes standard output and standard error to pipes.

    You'll either have to read these pipes yourself, which is the normal approach if your Perl script is generating output that your Java process is interested in, or you can have them inherit the Java process's streams by calling the methods such as pb.redirectOutput(ProcessBuilder.Redirect.INHERIT); for each stream you want to inherit, or simply pb.inheritIO(); to inherit all three stdin/out/err streams. You should also inspect the Process's exitValue() to see if it's zero (normal exit) or not.

    Hope this helps,
    -- Hauke D

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1164639]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-25 12:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found