Questions tagged [runtime.exec]

The Runtime.exec() method allows Java apps. to create a new OS Process.

The Runtime.exec(...) method (which has 6 overloaded variants) allows Java apps. to create a new system (represented in Java as a Process).

There are common mistakes made when creating new processes - as detailed in When Runtime.exec() won't. The article is the first thing to check if a process fails. Implement all the tips, and even if doing so does not make the process work, it will provide much more detailed information on why it failed.

The ProcessBuilder class introduced in Java 1.5 makes it easier to create and use a process correctly. For example, the redirectErrorStream(boolean) convenience method will merge the System.out & System.err streams, which allows both streams to be consumed in one Thread.

881 questions
15
votes
5 answers

Running a java program from another java program

I am working on a simple java program. It simply compiles and executes another java program. I am using Runtime.exec() function to compile and run. There is no problem with compilation. but when it runs, if the second program needs an input to read…
AKA
  • 5,479
  • 4
  • 22
  • 36
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
13
votes
2 answers

Unexpected different results from the same String input

I have a BroadcastReceiver that receives input from an outside source. This receiver must then behave as a "mouse-like" program and send input events to the system. I have Root access and permissions. My problem is that when I send a String such as…
Bonatti
  • 2,778
  • 5
  • 23
  • 42
13
votes
5 answers

java Runtime.getRunTime().exec & wildcards?

i'm trying to remove junk files by using Process p = Runtime.getRuntime().exec(); it works fine as long as i do not use wildcards, i.e. this works: Process p = Runtime.getRuntime().exec("/bin/rm -f specificJunkFile.java"); while the following…
Jakob
  • 872
  • 10
  • 26
13
votes
1 answer

Having spaces in Runtime.getRuntime().exec with 2 executables

I have a command that I need to run in java along these lines: C:\path\that has\spaces\plink -arg1 foo -arg2 bar "path/on/remote/machine/iperf -arg3 hello -arg4 world" This command works fine when the path has no spaces, but when I have the…
pwatt01
  • 155
  • 1
  • 1
  • 9
12
votes
5 answers

Runtime.exec().waitFor() not actually waiting for

I've got some code that uses Runtime.exec() to run an external .jar (built as an IzPack installer). If I run this external.jar from the command line like so: java -jar external.jar Then the command prompt does not return control until the…
Rhys
  • 1,439
  • 1
  • 11
  • 23
11
votes
1 answer

How To Run Mac OS Terminal Commands From Java (Using Runtime?)

I've been looking up ways to run external programs using Java's runtime. This works fine, for instance: String[] cmd = {"mkdir", "test"}; Runtime.getRuntime().exec(cmd); Creates a new directory as you would expect. Now, from a bash window in Mac I…
mtrc
  • 1,317
  • 3
  • 16
  • 39
10
votes
2 answers

piping output of ProcessBuilder to another ProcessBuilder

Is it possible to pass the output of one process created by ProcessBuilder to another process created by another ProcessBuilder? For example, if I'm trying to execute this shell command: ls | grep build.xml how should I do it with…
ndriks
  • 359
  • 6
  • 16
10
votes
1 answer

Is there an alternative to Runtime.getRuntime().exec()

Just wondering, if there is something better, newer, safer, faster, etc than Runtime.getRuntime().exec(). I want to run another process from my application on linux, and this is the only way i know how. Would be nice to have an alternative.
LoudNPossiblyWrong
  • 3,855
  • 7
  • 33
  • 45
10
votes
2 answers

What is the purpose of Process class in Java?

Runtime objRuntime = Runtime.getRuntime(); String strBackupString = "mysqldump -u " + userName + " -p" + password + " " + dbName; Process objProcess = objRuntime.exec(strBackupString); This is used for backup of database. But what exactly happens?…
TCM
  • 16,780
  • 43
  • 156
  • 254
10
votes
3 answers

Start CMD by using ProcessBuilder

I am trying to start the CMD application in windows by using the following code, but it doesn't work as expected. Several examples from different websites shows that "cmd" as an argument in the ProcessBuilder construct should work. What do I have to…
Birdman
  • 5,244
  • 11
  • 44
  • 65
9
votes
4 answers

How to set an environment variable in Java using exec?

Possible Duplicate: How do I set environment variables from Java? I'm trying to set an environment variable, and read it back to verify it was actually set. I've got the following : import java.io.IOException; public class…
Jimmy
  • 16,123
  • 39
  • 133
  • 213
9
votes
3 answers

java Runtime process - check if waiting for input

I wish to create a process using java's runtime: for example. Process proc = Runtime.getRuntime().exec("cmd"); Then, I want to somehow wait for the process until it is in 'ready for input' state, which will verify it has finished all of its work.…
ComputeALot
  • 101
  • 1
  • 3
9
votes
1 answer

ProcessBuilder vs Runtime.exec()

I'm trying to create a frontend app in Java to handle batch SVG conversions using Inkscape's command line feature. I'm taking and updating the code from https://sourceforge.net/projects/conversionsvg/. The way the original developer handled calling…
8
votes
4 answers

Launching wkhtmltopdf from Runtime.getRuntime().exec(): never terminates?

I'm launching wkhtmltopdf from within my Java app (part of a Tomcat server, running in debug mode within Eclipse Helios on Win7 64-bit): I'd like to wait for it to complete, then Do More Stuff. String cmd[] = {"wkhtmltopdf", htmlPathIn,…
Mark Storer
  • 15,672
  • 3
  • 42
  • 80
1 2
3
58 59