Reputation: 3469
I have a process builder, And for some reason It won't work.. I have a jar file called "test.jar" It's got one class, with this code..
package me.thefiscster510.debugger;
public class Main {
public static void main(String[] args){
System.out.print(System.getenv("APPDATA"));
System.exit(0);
}
}
I then have another jar that has a button, this is the buttons Event Handler..
public class buttonhandler implements ActionListener{
@Override
public void actionPerformed(ActionEvent arg0){
// TODO Auto-generated method stub
ProcessBuilder pb;
try {
pb = new ProcessBuilder("java", "-jar", "test.jar");
pb.environment().put("APPDATA", textfield.getText() == null ? System.getenv("APPDATA") : textfield.getText());
Process p = pb.start();
}catch(IOException e){
e.printStackTrace();
}
}
}
The code doesn't do anything.. Like, It just sits there.. Doesn't put anything in the console, Nothing.. Can someone tell me what's going on?
Upvotes: 0
Views: 258
Reputation: 2009
If you are using Java7 you should call pb.inheritIO()
before starting the process. That will redirect the process's standard output and error to your parent java process's streams. Then you should see it output to the console.
If you are not on Java7, then you need to capture the standard output of the child process by calling p.getInputStream()
Then you can copy that data to your standard output. Simplest way to do that is with IOUtils.copy
Upvotes: 1