Questions tagged [processbuilder]

Processbuilder is Java wrapper around an Operating System Process. This class is used to create operating system processes.

From the Javadoc:

Each ProcessBuilder instance manages a collection of process attributes. The start() method creates a new Process instance with those attributes. The start() method can be invoked repeatedly from the same instance to create new subprocesses with identical or related attributes.

1509 questions
111
votes
12 answers

ProcessBuilder: Forwarding stdout and stderr of started processes without blocking the main thread

I'm building a process in Java using ProcessBuilder as follows: ProcessBuilder pb = new ProcessBuilder() .command("somecommand", "arg1", "arg2") .redirectErrorStream(true); Process p = pb.start(); InputStream stdOut =…
LordOfThePigs
  • 11,050
  • 7
  • 45
  • 69
110
votes
4 answers

Difference between ProcessBuilder and Runtime.exec()

I'm trying to execute an external command from java code, but there's a difference I've noticed between Runtime.getRuntime().exec(...) and new ProcessBuilder(...).start(). When using Runtime: Process p = Runtime.getRuntime().exec(installation_path +…
gal
  • 1,111
  • 2
  • 8
  • 5
90
votes
5 answers

Call an executable and pass parameters

I'm figuring out a mechanism to call an exe from Java and passing in specific parameters. How can I do? Process process = new ProcessBuilder("C:\\PathToExe\\MyExe.exe").start(); InputStream is = process.getInputStream(); InputStreamReader isr = new…
Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
88
votes
18 answers

How to get PID of process I've just started within java program?

I've started a process with following code ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "path"); try { Process p = pb.start(); } catch (IOException ex) {} Now I need to know the process's pid that I've just started.
raf
  • 1,121
  • 3
  • 13
  • 14
87
votes
13 answers

How to redirect ProcessBuilder's output to a string?

I am using the following code to start a process builder.I want to know how can I redirect its output to a String. ProcessBuilder pb = new ProcessBuilder( System.getProperty("user.dir") + "/src/generate_list.sh", filename); Process p =…
Ankesh Anand
  • 1,695
  • 2
  • 16
  • 24
41
votes
2 answers

ProcessBuilder gives a "No such file or directory" while Runtime().exec() works fine

I have an application, running on the Playframework, which needs to encode some video files. I used Process pr = Runtime.getRuntime().exec(execCode) for this (and it works perfectly), but as I need both, the output stream and the error stream, I…
Luuk D. Jansen
  • 4,402
  • 8
  • 47
  • 90
39
votes
1 answer

How can I run a subprocess in Equinox with dynamic bundle installation?

I have a Java application that runs in OSGi/Equinox. From this application, I need to spawn Java subprocesses (e.g. via ProcessBuilder.start()) that run in OSGi/Equinox as well in order to handle class loading correctly. The subprocess will require…
mapeters
  • 1,067
  • 7
  • 11
38
votes
10 answers

Java ProcessBuilder: Resultant Process Hangs

I've been trying to use Java's ProcessBuilder to launch an application in Linux that should run "long-term". The way this program runs is to launch a command (in this case, I am launching a media playback application), allow it to run, and check to…
Matt D
  • 1,476
  • 3
  • 17
  • 26
37
votes
1 answer

How to set working directory with ProcessBuilder

I am trying start a process in my home directory in ubuntu. I keep getting a permission denied exception and I have no idea why. Here is the code: Process p = null; ProcessBuilder pb = new ProcessBuilder("/home"); p = pb.start(); Here is the…
Eric
  • 718
  • 1
  • 9
  • 22
29
votes
9 answers

What can cause Java to keep running after System.exit()?

I have a Java program which is being started via ProcessBuilder from another Java program. System.exit(0) is called from the child program, but for some of our users (on Windows) the java.exe process associated with the child doesn't terminate. The…
uckelman
  • 25,298
  • 8
  • 64
  • 82
26
votes
2 answers

ProcessBuilder redirected to standard output

I would like to redirect a java process output towards the standard output of the parent java process. Using the ProcessBuilder class as follows: public static void main(String[] args) { ProcessBuilder processBuilder = new ProcessBuilder("cmd"); …
John
  • 261
  • 1
  • 3
  • 3
23
votes
3 answers

Java ProcessBuilder to start execute multiple commands sequentially in Linux

I would like to execute 2 or more commands sequentially through my Java Application using ProcessBuilder class. I Have tried multiple options as suggested in other responses/forums but no luck. Here are the things I have tried: ProcessBuilder…
Narinder Kumar
  • 461
  • 1
  • 5
  • 9
20
votes
3 answers

ProcessBuilder and Process.waitFor(), how long does it wait?

I am executing an .exe-file from java, using the ProcessBuilder class and the Process class. To explain what I am doing: builder = new ProcessBuilder(commands); builder.redirectErrorStream(true); Process process = builder.start(); …
KJaeg
  • 698
  • 3
  • 7
  • 23
19
votes
2 answers

ProcessBuilder environment variable in java

I'm trying to add a environment variable for a ProcessBuilder object but then when I call on that new variable in the ProcessBuilder I get an error. this is how I build the Process public class OTU { public static void main(String[] args) throws…
Julio Diaz
  • 9,067
  • 19
  • 55
  • 70
17
votes
10 answers

Executing another application from Java

I need to execute a batch file which executes another Java application. I don't care whether it executes successfully or not and I don't have to capture any errors. Is it possible to do this with ProcessBuilder? What are the consequences if I do not…
user234194
  • 1,683
  • 10
  • 38
  • 56
1
2 3
99 100