Not able to invoke Perl script from Java -


I am trying to open Perl script from Java but it seems that I am not able to do this.

This is my Perl script which creates a file. This is a simple script.

  Use strict; Use warnings; Open (my $ FH, '& gt;', 'report.txt'); Print $ FH "My first report generated by Perl \ n"; About $ FH; Print "done \ n";  

Here is my Java code that is using above Perl script.

  package perlfromjava; Import java.io.IOException; Import java.util.logging.Level; Import java.util.logging.Logger; Public category PerlFromJava {public static zero main (string [] args) {try {string command = "perl $ HOME / documents / hello.pl"; Println (order); Proc proc = Runtime.getRuntime (). Exec (command); } Hold (IOException pre) {Logger.getLogger (PerlFromJava.class.getName ()). Log (Level.SEVERE, null, ex); }}}  

When I run the Perl script command, it is working perfectly, but when I am implementing Perl script from Java, report . Txt file is not being created.

Why is this happening?

Thank you

Your code is actually working. But the problem is that the file created by the copy is created in the public file. If you are using an ideal file then that file is definitely created inside that project folder. If you search for "report.txt" then you find the file. Change your Perl script to understand

  Use Strict; Use warnings; Open (my $ FH, '& gt;', 'C: / user / MHADA .se / desktop / js / rp. Txt'); Print $ FH "My first report generated by Perl \ n"; About $ FH; Print "done \ n";  

intead report. Txt provides full path, where you report in perl script. Create a Txt file. And see if it's working.

  try {string command = "pearl c: \\ user \\ madawa \" desktop \\ js \\ mm.pll "; Process process = runtime.gettime (). Exec (command); Process.waitFor (); If (process.exitValue () == 0) {System.out.println ("successful command"); } And {System.out.println ("command failure"); }} Hold (exception e) {System.out.println ("exception:" + e.toString ()); }  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -