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.

1403 questions
101
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,021
  • 2
  • 8
  • 5
96
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
  • 10,378
  • 5
  • 41
  • 64
88
votes
4 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,006
  • 23
  • 110
  • 185
75
votes
17 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
  • 961
  • 2
  • 11
  • 14
70
votes
10 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,384
  • 1
  • 12
  • 23
37
votes
1 answer

ProcessBuilder gives a "No such file or directory" on Mac 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,120
  • 7
  • 41
  • 86
35
votes
9 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,406
  • 3
  • 17
  • 25
34
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
  • 688
  • 1
  • 9
  • 22
28
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
  • 23,160
  • 8
  • 54
  • 76
22
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
  • 221
  • 1
  • 2
  • 3
18
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
  • 381
  • 1
  • 3
  • 8
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,623
  • 9
  • 35
  • 54
16
votes
0 answers

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
  • 848
  • 5
  • 11
15
votes
1 answer

Using scala.sys.process with timeout

I find it extreemly cool to use standard syntax like import scala.sys.process._ val countLogger = ProcessLogger(line => {println ("out line: " + line)}, line => {println ("err line: " + line)}) val exitCode…
Val
  • 1
  • 8
  • 38
  • 59
15
votes
2 answers

Elevating a ProcessBuilder process via UAC?

I'm trying to run an external executable, but apparently it needs elevation. The code is this, modified from an example of using ProcessBuilder (hence the array with one argument) : public static void main(String[] args) throws IOException { …
Kitty Kymaera
  • 155
  • 1
  • 6
1
2 3
93 94