0

I've created a java GUI using NetBeans v.8.2. Very new to Java.

One of the buttons in the GUI launches a shell script (I am aware that this is not ideal Java practice, but it is appropriate for my use case) using arguments gathered from other buttons/text fields in the GUI:

    ```
        private void RunMacActionPerformed(java.awt.event.ActionEvent evt) {                                       
            String command[] = {scriptDirStr + "/./Master_run.sh",
                                projDirStr+"/",
                                DestDirStr+"/",
                                ECnonNormStr,
                                ECnormStr,
                                ProjID.getText(),
                                scriptDirStr +"/"};
            System.out.print(Arrays.toString(command));
            ProcessBuilder pb = new ProcessBuilder(command);
            try {
                Process p = pb.start();
            } catch (IOException ex) {
                Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }                                      
    ```

So, the idea is to launch Master_run.sh with a bunch of arguments. Master_run.sh runs other R and python scripts, e.g.:

python2 $script_Path/array_data_extractor.py $spath >>$spath/masterOutput.txt 2>>$spath/masterErrors.txt

and

Rscript $script_Path/1_APS_generator_master.R $spath $dpath $APS_src_filename $project_ID $APS_norm_src_filename >>$spath/masterOutput.txt 2>>$spath/masterErrors.txt

and ends with

cat $spath/masterErrors.txt| mail -s $Project_title" done" [email protected]

I know the script gets launched because I get an email with the following errors:

"...line 14: python2: command not found"

and

"...line 16: Rscript: command not found"

When I run Master_run.sh with the same exact arguments from within the terminal, there are no such errors. Does anybody know what might be going wrong and/or how to fix it?

To rephrase the problem, it seems I am getting different behavior launching the same commands from within java vs. directly onto the command line.

1 Answer 1

2

Your shell environment is clearly different from java's environment. Try specifying the full path to python2 and Rscript. For example

/usr/local/bin/python2 $script_Path/array_data_extractor.py ...
Sign up to request clarification or add additional context in comments.

1 Comment

Could sourcing my .bash_profile from within the script do the trick?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.