简体   繁体   中英

Can not get output of Runtime.getRuntime().exec(python script);

I'm trying to write a output file of a python script using java exec, however I get no output. I got the expected file however is empty. I made a script do what I want.

#!/bin/bash/
cd /home/taste/work/AIR/air/
python configure -f .air_config

I have already tried to execute this script from the shell and I can get the output.

Process p = Runtime.getRuntime().exec(new String[]{"bash","-c","sh 
./Configuration_Data/Scripts/"+cF.folderName+"/testConfigure.sh > 
configureOut.txt"});

This is the way I'm reading :

  String line ="";
  //Used to create output
  StringBuilder text  = new StringBuilder();
  BufferedReader input = new BufferedReader(new 
  InputStreamReader(p.getInputStream()));

  while ((line = input.readLine()) != null) {
    text.append(line+"\n");
    System.out.println(line);
  }

I would like to have output from my python file.

Thank you.

Since you direct the script's output with > configureOut.txt to the file, there's simply nothing left to read from the input stream. If you really want the output in both the file and the input stream, you could change the above redirection to | tee configureOut.txt | tee configureOut.txt .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM