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
4
votes
2 answers
How to start a program and exit immediately using apache commons-exec?
By using Apache Commons-Exec I can start a program successfully, however the starter program suspended after the program started.
May I ask how to start a program and exit immediately so it will not block the following execution?
DefaultExecutor…

Mike
- 3,515
- 10
- 44
- 67
3
votes
1 answer
Apache Commons Exec Problems Handling Regex Argument?
I'm trying to use Apache Commons Exec to run a git command which uses a regex.
When I form my CommandLine and print it out it looks like this:
[git, --no-pager, grep, --line-number, --untracked, --extended-regexp, "^\s*public…

ragurney
- 424
- 5
- 16
3
votes
3 answers
How to prevent log output from Apache Commons Exec
I am using Apache Commons Exec on a web application in JBoss 4.2.3. Whenever I call Apache Exec it outputs all the console output in the log and this is a lot of output and it could easily fill in my logs in a production environment. How can I…

Alex
- 616
- 1
- 12
- 28
3
votes
5 answers
How to execute /bin/sh with commons-exec?
This is what I'm doing:
import org.apache.commons.exec.*;
String cmd = "/bin/sh -c \"echo test\"";
new DefaultExecutor().execute(CommandLine.parse(cmd));
This is the output:
/bin/sh: echo test: command not found
What am I doing wrong?

yegor256
- 102,010
- 123
- 446
- 597
3
votes
3 answers
Apache Commons exec PumpStreamHandler continuous input
I am trying to solve interaction with command line process using Apache Commons exec. I'm stuck with following code:
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream ins = new ByteArrayOutputStream();
OutputStreamWriter…

MichalVales
- 415
- 4
- 10
3
votes
2 answers
Better way to run pipe command using apache commons exec
I am using apache commons exec to run command: arp | wc -l
Below is my code:
private String runCommand(String cmd, String params) {
CommandLine commandLine = new CommandLine(cmd);
commandLine.addArguments(params);
…

ojas
- 2,150
- 5
- 22
- 37
3
votes
1 answer
Read stdout stream from subprocess as it becomes available
In my Java application, I need to execute some scripts as subprocesses and monitor the output on stdout from Java so that I can react when necessary to some output.
I am using apache commons-exec to spawn the subprocess and redirect stdout of the…

apatrick
- 194
- 2
- 14
3
votes
2 answers
commons-exec: hanging when I call executor.execute(commandLine);
I have no idea why this is hanging. I'm trying to capture output from a process run through commons-exec, and I continue to hang. I've provided an example program to demonstrate this behavior below.
import java.io.DataInputStream;
import…

Stefan Kendall
- 66,414
- 68
- 253
- 406
3
votes
1 answer
Executing an external program using process builder or apache commons exec
I need to execute an external application which returns large data (takes more than 2 hours to complete ) nand which continuously outputs data.
What I need to do is execute this program asynchronously and capture the output in a file.
I tried using…

coder
- 95
- 2
- 13
2
votes
0 answers
Apache commons exec run interactive terminal application
First of all I'd like to say that I read all the other threads concerning apache commons exec. I have a terminal based executable. When ran, it prompts the user for some input from command line. I need to run this program from within my java program…

electrique
- 431
- 6
- 18
2
votes
2 answers
Handling empty argument to CommandLine in Commons Exec
I am trying to execute a bash script that takes 3 parameters from Java, following is the code where I create the command line
CommandLine command = new…

Salman A. Kagzi
- 3,833
- 13
- 45
- 64
2
votes
1 answer
Error while running command consist of multiple parameters using apache commons exec
I am having trouble while running following command using apache commons exec: sysctl -n net.ipv4.neigh.default.gc_thresh3
The problem is it is giving the following error:
Exception in thread "main" java.lang.RuntimeException: Could not run command…

ojas
- 2,150
- 5
- 22
- 37
2
votes
0 answers
git commands through cmd in java and get whole console output
I want to perform git commands through cmd in java and want to validate the whole output received.
Expected:
Cloning into 'gitrepo'...
remote: Counting objects: 92, done
remote: Finding sources: 100% (92/92)
remote: Getting sizes: 100%…

Anu Chawla
- 415
- 1
- 4
- 19
2
votes
1 answer
Use docker-machine create from java
I have an application that (I want to) uses Java to start and stop Docker containers. It seems that the way to do this is using docker-machine create, which works fine when I test from the command line.
However, when running using Commons-Exec from…

Kyle
- 401
- 4
- 10
2
votes
1 answer
Apache Commons Exec Change PATH and Execute virtualenv's pip
I'm having some difficulty using the Apache Commons Exec library to change the PATH environment variable to point to a created Python virtualenv in my target directory.
Ideally, I want something that is equivalent to activating the Python…

Lucas
- 2,514
- 4
- 27
- 37