Not able to invoke Perl script from Java -
i trying invoke perl script java seems not able it.
here perl script creates file. simple script.
use strict; utilize warnings; open(my $fh, '>', 'report.txt'); print $fh "my first study generated perl\n"; close $fh; print "done\n";
here java code invoking above perl script.
package perlfromjava; import java.io.ioexception; import java.util.logging.level; import java.util.logging.logger; public class perlfromjava { public static void main(string[] args) { seek { string command = "perl $home/documents/hello.pl"; system.out.println(command); process proc = runtime.getruntime().exec(command); } grab (ioexception ex) { logger.getlogger(perlfromjava.class.getname()).log(level.severe, null, ex); } } }
when running perl scrip command like, working when invoking perl script java, report.txt file not getting created.
why happening?
thanks
actually code working .but problem file created perl generated in run java file.if using ide file has certainly created within of project folder .if search "report.txt" find file.to understand alter perl script to
use strict; utilize warnings; open(my $fh, '>', 'c:/users/madhawa.se/desktop/js/report.txt'); print $fh "my first study generated perl\n"; close $fh; print "done\n";
intead give report.txt give total path u create report.txt file in perl script .and see it's working.
seek { string command = "perl c:\\users\\madhawa.se\\desktop\\js\\mm.pl"; process process = runtime.getruntime().exec(command); process.waitfor(); if (process.exitvalue() == 0) { system.out.println("command successful"); } else { system.out.println("command failure"); } } grab (exception e) { system.out.println("exception: " + e.tostring()); }
java perl
No comments:
Post a Comment