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
8
votes
3 answers

Alternatives to Runtime and ProcessBuilder (Java)

I am interested if anyone has an idea on how to run unix commands without using runtime or ProcessBuilder in a java application
tosi
  • 1,873
  • 2
  • 18
  • 38
8
votes
5 answers

How to pipe InputStream to ProcessBuilder

Please move down to the 2nd update. I didn't want to change the previous context of this question. I'm using wkhtmltoimage from a Java app. The standard way of using it is - path-to-exe http://url.com/ image.png. According to their docs, if we write…
Hrishikesh Choudhari
  • 11,617
  • 18
  • 61
  • 74
7
votes
2 answers

ProcessBuilder debugging

I created an executable jar and executed it using process builder from another java program. Here's my code - public class SomeClass { public static void main(String[] args) { Process p = null; ProcessBuilder pb = new ProcessBuilder("java",…
Vivek Rao
  • 576
  • 4
  • 25
7
votes
1 answer

EXE crash when calling from ProcessBuilder in java

I am invoking some EXE's(7za.exe, pg_basebackup.exe, ...) from JAVA ProcessBuilder. It is working without any issues for 2 or 3 days (EXE will be called daily). After that EXE's are crashing continuously. 7za.exe error: Exit code ::…
Aravindharaj G
  • 407
  • 5
  • 16
7
votes
1 answer

Start another Process with System.console available

I have a two programs: first, that uses Console object to read and write data second, that should run first with some dynamically calculated arguments Second program code looks like this: String[] arguments = { "cmd", "/c", "java", "-cp",…
Ivan
  • 490
  • 1
  • 7
  • 23
7
votes
3 answers

executing commands on terminal in linux through java

I have created an standalone application in which i want that when the user clicks on the run button then the terminal should open and a particular command should be executed on the terminal. I am able to open the terminal successfully using the…
Harshit Agarwal
  • 1,345
  • 3
  • 20
  • 27
7
votes
2 answers

Running jar with Processbuilder doesn't work properly

I have the following code: ProcessBuilder pb = new ProcessBuilder( "java", "-jar", "test.jar", Integer.toString( jobId ), Integer.toString( software ), Integer.toString( entryPoint ), application ); pb.directory( new File("/home/userName/TestBSC")…
progNewbie
  • 4,362
  • 9
  • 48
  • 107
7
votes
2 answers

Java - start another class' main in a different process

I need a clean way to start many instances of a Java program with a GUI, and I want to do it programmatically. The "program" i want to run is just a .class file (a compiled .java file with a main method), it should show a GUI and run independently…
Agostino
  • 2,723
  • 9
  • 48
  • 65
7
votes
3 answers

gradle: Execute task "type:Exec" with many arguments with spaces

I have the gradle task that should create Websphere profile on Windows OS task createProfile(type:Exec) { def commandToExecute = new StringBuffer() def profile = 'AppSrv02' def wasHome = 'C:/IBM new/WebSphere/AppServer' def str =…
serg
  • 1,003
  • 3
  • 16
  • 26
7
votes
1 answer

Concurrency issue between waiting for a process and reading the stream?

I use a ProcessBuilder to run processes. I handle Input/Output streams by submitting the corresponding runnables handling them in a thread pool (Executors.newCachedThreadPool()). I get the result but every now and then I don't get anything. For…
Jim
  • 18,826
  • 34
  • 135
  • 254
6
votes
1 answer

Executing "echo" using Java ProcessBuilder doesn't interpolate variables (outputs the string "$PATH")

I want to echo the PATH variable, with the goal to get the same output from a Java ProcessBuilder as running echo $PATH in the terminal. However, when it executes the output is actually $PATH instead of the value of the PATH variable. I wonder if…
Aaron Silverman
  • 22,070
  • 21
  • 83
  • 103
6
votes
2 answers

Subprocess started from Java finishes using waitFor but streams aren't terminated

I am using Java's ProcessBuilder to start a subprocess, which is another Java program that has to run in a separate JVM. I start two Threads to read from the stdout and stderr streams from the Process, so that there is no hang if the stream buffers…
6
votes
2 answers

Redirecting the output of a process into the input of another process using ProcessBuilder in Java

I have two processes defined by processBuilders: ProcessBuilder pb1 = new ProcessBuilder (...) ProcessBuilder pb2 = new ProcessBuilder (...) I want the output of pb1 to be the input to pb2. I found in the documentation that I can make the input of…
Evgenii.Balai
  • 939
  • 13
  • 30
6
votes
1 answer

Execute a shell command using processBuilder and interact with it

I'm trying to create a program allowing me to execute a command through a terminal (which is OmxPlayer for raspberry pi if you want to know) with arguments, but i'd want to be able to interact with it once I have launched the command. For example…
Equinox
  • 137
  • 1
  • 1
  • 9
6
votes
2 answers

opening a shell and interacting with its I/O in java

I am trying to open a shell (xterm) and interact with it (write commands and read the shell's output) Here is a sample of code which won't work: public static void main(String[] args) throws IOException { Process pr = new…
royeet
  • 829
  • 1
  • 9
  • 12