NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Not able to run perl scripts via my java

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
mah



Joined: 22 Nov 2017
Posts: 1

PostPosted: Wed Nov 22, 2017 1:41 pm    Post subject: Not able to run perl scripts via my java Reply with quote

Within the Netbeans, I want to execute a perl script with ProcessBuilder, but it seems that the the environment variables and other things that normally work via the terminal, won't work with the netbeans.

Code:
        try {
          String[] cmdline = {"/usr/bin/perl", "/home/mahmood/src/temp.pl"};
          final ProcessBuilder pb = new ProcessBuilder(cmdline);
          pb.inheritIO();
          final Process p = pb.start();
          int exitCode = p.waitFor();
          if (exitCode != 0) {
            throw new IOException("... Perl failed :( \n");
          }
       } catch (IOException e) {    // for the failed exit code
         System.out.println(e.getMessage() );
       } catch (InterruptedException e) {  // for waitFor()
         System.out.println(e.getMessage() );
       }   


And the perl script is

Code:
use Bio::SeqIO;
print "Hello\n";


Debugging this code with Netbeans, always go to the IOException and I see the following error message on the output window
Code:
Can't locate Bio/SeqIO.pm in @INC (you may need to install the Bio::SeqIO module)


That is totally incorrect, because I can run the perl script via the terminal, e.g. bash. If I drop the use statement, then ProcessBuilder works fine. How can I fix that?
Back to top
priya465



Joined: 17 Aug 2017
Posts: 35

PostPosted: Tue Nov 28, 2017 6:50 am    Post subject: Reply with quote

Try adding:

use FindBin;
use lib $FindBin::RealBin;
This will add the directory that the script is in to the library search path.

Edit: The shell script is not working because it changes the environment of the shell process, not the Java process that spawned it.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo