linux - Not able to see the Perl output executing from Java class -
i using java class execute perl script on linux box. .class being created successfully. when execute class, says exit code successful sop, i'm not able see perl output or execution of script. if execute perl directly, works fine...
this perl script:
#!/usr/local/bin/perl print ("enter distance converted:\n"); $originaldist = <stdin>; chop ($originaldist); $miles = $originaldist * 0.6214; $kilometers = $originaldist * 1.609; print ($originaldist, " kilometers = ", $miles, " miles\n"); and java class call script:
import java.io.inputstream; import java.io.inputstreamreader; import java.io.bufferedreader; import java.io.ioexception; class test { public static void main(string[] args) throws ioexception { string[] acmdargs = { "perl", "-e" , "pl newprg.pl" }; runtime oruntime = runtime.getruntime(); process oprocess = null; try { oprocess = oruntime.exec(acmdargs); oprocess.waitfor(); } catch (exception e) { system.out.println("error executing " + acmdargs[0]); } /* dump output stream */ bufferedreader = new bufferedreader ( new inputstreamreader(oprocess.getinputstream())); string sline; while ((sline = is.readline()) != null) { system.out.println(sline); } system.out.flush(); /* print final result of process */ system.err.println("exit status=" + oprocess.exitvalue()); return; } }
two issues:
perl -e pl newprg.plnot execute program command line, fail parse given (non) expression. meant useperl newprg.pl- your program requires input, need pipe in using output stream of process
for example:
try { oprocess = oruntime.exec(acmdargs); printwriter writer = new printwriter(new outputstreamwriter( oprocess.getoutputstream())); writer.println(200); writer.close(); oprocess.waitfor(); } catch (exception e) { system.out.println("error executing " + acmdargs[0]); }
Comments
Post a Comment