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
17
votes
2 answers

Runtime.getRuntime().exec(cmd) hanging

I am executing a command which returns me the Revision number of a file; 'fileName'. But if there is some problem executing the command, then the application hangs up. What can I do to avoid that condition? Please find below my code. String cmd=…
user1688404
  • 729
  • 3
  • 9
  • 19
16
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
  • 165
  • 1
  • 6
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
  • 40
  • 64
14
votes
1 answer

ProcessBuilder vs Runtime.exec()

Which one is better? By better I mean which one has better security, etc. (not ease of use).
JavaIsGreat
  • 945
  • 1
  • 9
  • 10
14
votes
1 answer

How to set PATH environment variable in ProcessBuilder java in windows

I am trying to set the PATH environment variable for the process builder in java, I tried the following: ProcessBuilder pb = new ProcessBuilder(command); Map mp = pb.environment(); mp.put("Path", "myPath"); pb.start(); But the…
Destructor
  • 3,154
  • 7
  • 32
  • 51
13
votes
1 answer

Start a Java process at low priority using Runtime.exec / ProcessBuilder.start?

I'm trying to start an external process via Java using the ProcessBuilder class, and that much works. Currently running using the command: new ProcessBuilder("java", "-jar", jarfile, args); What I would like to do is just this, but to start the…
Andrew
  • 617
  • 2
  • 6
  • 19
13
votes
2 answers

Why does process hang if the parent does not consume stdout/stderr in Java?

I know that if you use ProcessBuilder.start in Java to start an external process you have to consume its stdout/stderr (e.g. see here). Otherwise the external process hangs on start. My question is why it works this way. My guess is that JVM…
Michael
  • 41,026
  • 70
  • 193
  • 341
13
votes
5 answers

ProcessBuilder adds extra quotes to command line

I need to build the following command using ProcessBuilder: "C:\Program Files\USBDeview\USBDeview.exe" /enable "My USB Device" I tried with the following code: ArrayList test = new ArrayList(); test.add("\"C:\\Program…
stefan.at.kotlin
  • 15,347
  • 38
  • 147
  • 270
13
votes
6 answers

Setting the environment for ProcessBuilder

I have a strange problem setting the Linux environment from Java (1.6); specifically the "PATH" variable. In a nutshell, I have a pipeline for running native processes, which uses java.lang.ProcessBuilder. The user can optionally set the environment…
Andrew Reid
  • 173
  • 1
  • 1
  • 7
12
votes
2 answers

ProcessBuilder can't find file?!

Another question in quick succession but this has to be a really obvious error that I am not seeing. I've written some code to run a batch file below but I'm getting an error message saying it cannot find the file but I can assure you that the file…
Rookie
  • 1,879
  • 3
  • 17
  • 18
11
votes
3 answers

Java, Runtime.exec or ProcessBuilder: how to know if the file is shell or binary?

I'm looking into a most efficient way to decide: Should I preprend the user-provided command line with the shell executable If yes, what would that executable be? (/bin/sh? /usr/bin/perl? /usr/bin/ksh? c:/../cmd.exe?) It is known that to start a…
11
votes
3 answers

pass multiple parameters to ProcessBuilder with a space

I would like to pass multiple parameters to a processBuilder and the parameters to be separated by a space. Here is the command, String[] command_ary = {dir+"library/crc"," -s ", fileName," ",addressRanges}; I need to provide a space after "fcrc"…
mee
  • 821
  • 5
  • 12
  • 28
10
votes
2 answers

java.io.IOException: error=11

I am experiencing a weird problem with the Java ProcessBuilder. The code is shown below (in a slightly simplified form) public class Whatever implements Runnable { public void run(){ //someIdentifier is a randomly generated string …
mbatchkarov
  • 15,487
  • 9
  • 60
  • 79
10
votes
2 answers

How to stop a command being executed after 4-5 seconds through process builder?

Reference code : ProcessBuilder ps4; Process pr4 = null; String batchFile3 = new File(path + "/src/example.sh"); ps4 = new ProcessBuilder(batchFile3.getAbsolutePath()); ps4.redirectErrorStream(true); ps4.directory(new File(path + "/src/")); pr4…
Ganesh S
  • 307
  • 2
  • 3
  • 9
10
votes
3 answers

Process.exitValue() and Process.destroy() features

I have been experimenting with Process and ProcessBuilder and come with this SSCCE. import java.io.IOException; public class TestProcess { public static void main(String[] args) { Process process = null; …
Nikolay Kuznetsov
  • 9,467
  • 12
  • 55
  • 101