Apache Commons Exec is a Java library that makes it easier to launch external processes from a Java application.
Questions tagged [apache-commons-exec]
87 questions
29
votes
4 answers
Process output from apache-commons exec
I am at my wits end here. I'm sure this is something simple and I most likely have huge holes in my understanding of java and streams. I think there are so many classes that I'm a bit overwhelmed with trying to poke through the API to figure out…

James DeRagon
- 364
- 1
- 4
- 11
27
votes
6 answers
Deciding between Apache Commons exec or ProcessBuilder
I am trying to decide as to whether to use ProcessBuilder or Commons exec,
My requirements are that I am simply trying to create a daemon process whose stdout/stdin/stderr I do not care about. In addition I want to execute a kill to destroy this…

Traker
- 2,147
- 3
- 23
- 38
11
votes
2 answers
How to pipe a string argument to an executable launched with Apache Commons Exec?
I need to pipe a text argument to the stdin of a command launched with Apache Commons Exec (for the curious, the command is gpg and the argument is the passphrase to the keystore; gpg does not have an argument to provide the passphrase explicitly,…

wishihadabettername
- 14,231
- 21
- 68
- 85
10
votes
1 answer
Writing Output & Error to Log files using PumpStreamHandler
I have been searching for a while to get a good example for writing Process output & error stream to log file.
I use apache-commons exec library to execute my process. Following a code sample to demonstrate that
public static int…

Salman A. Kagzi
- 3,833
- 13
- 45
- 64
10
votes
5 answers
Apache Commons Exec produces too many quotes for arguments containing spaces?
Either there is a bug in Apache Commons Exec, or I am using the API wrong, but when I use the CommandLine class to add a argument that contains spaces, some quotes are added and are then part of the argument that is given.
For example: When I call…

roesslerj
- 2,611
- 5
- 30
- 44
9
votes
3 answers
Trouble providing multiple input to a Command using Apache Commons Exec and extracting output
I am writing a Java application that needs to use an external command line application using the Apache Commons Exec library. The application I need to run has a fairly long loading time so it would be preferable to keep one instance alive instead…

ftdube
- 191
- 1
- 7
9
votes
1 answer
Apache Commons Exec - sometimes a Thread can't open a local file in Linux
WARNING -- THE CAUSE IS NOT A MISSING FILE -- ALL THREADS ARE CALLING THE SAME SCRIPT FILE
I am starting 5-6 threads that call a local script in a Red Hat box.
I've noticed that sometimes, I get the following error message
couldn't read file…

Leo
- 751
- 4
- 29
7
votes
3 answers
Graceful kill of Apache Commons Exec process
I am starting an external process in my Java program (on Linux) and I need the ability to send it a SIGTERM signal rather than the SIGKILL that exec.getWatchdog().destroyProcess() is sending. Is there a way that I can more gracefully stop a unix…

jtb
- 889
- 11
- 27
6
votes
1 answer
How do I collect Standard Out and Standard Error separately when using Apache Commons Exec?
The below code gets all of the output, whether stdout or stderr.
String line = String.format("paty/to/script.py");
CommandLine cmd = CommandLine.parse(line);
DefaultExecutor executor = new DefaultExecutor();
ByteArrayOutputStream stdout = new…

Michael
- 455
- 7
- 18
6
votes
1 answer
commons-exec: Executing a program on the system PATH?
I'm trying to execute a program (convert from ImageMagick, to be specific) whose parent folder exists on the path. Ergo, when I run convert from the command line, it runs the command. The following, however, fails:
String command =…

Stefan Kendall
- 66,414
- 68
- 253
- 406
5
votes
4 answers
"Kill a process tree" on windows using Java
I have a Java webstart process that is part of a windows batch script. I'm using the javaws command in a batch script in this case.
This match script ( start.bat) is invoked programatically using the "apache commons exec". Under some conditions the…

Rajesh Kazhankodath
- 409
- 6
- 24
5
votes
3 answers
Do apache commons CommandLine objects protect against command line injection?
I want to use the org.apache.commons.exec Java library to call an executable. Does the CommandLine object protect against command line injection? For example, if I call:
String singleStringArgument = "-whatever;rm -rf ~/*"; // evil looking…

Timothy Jones
- 21,495
- 6
- 60
- 90
4
votes
2 answers
Streaming output with commons-exec?
Can anyone give me an example of how to stream the output of an external program executed with DefaultExecutor? I'm not finding any documentation describing how to do this.
My external process will run for several hours, so just grabbing all output…

Stefan Kendall
- 66,414
- 68
- 253
- 406
4
votes
0 answers
How to run interactive python script using apache common exec?
I am trying to run a python script using Apache Commons exec.I need to pass some values to python script as python script in an interactive one.How to do it?
My attempt was to set values in parent process's input stream.But it's not working for…

Abhijeet Panwar
- 1,837
- 3
- 26
- 48
4
votes
1 answer
rsync executed from java returns with file not found error
I am trying to execute a rsync command (atm testing locally) using Apache Commons Exec library and I get an error message, while executing the same command in terminal shows no problems.
This is the command I would like to execute:
rsync -zve "ssh…

Esch
- 79
- 1
- 5