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

Open new terminal, ssh to remote host and run a program to the remote host.All output to be viewed on new opened terminal

To be more specific, what i really want to do is to open two new terminals. From terminal_1 i want to ssh @host1 and run a program1 to host1. From terminal_2 i want to ssh @host2 and run a program2 to host2. I need the output of program1 to be…
Andreas
  • 3
  • 3
0
votes
2 answers

Runtime exec issues in Linux

In an application I am writing, I am launching another application (a runnable JAR) using Runtime.exec(...). Everything launches successfully in Windows, but Linux (specifically certain installations of CentOS - works in Ubuntu) has been giving me…
0
votes
2 answers

Unable to write commands onto an exe program on shared location using java

I've an exe program placed on shared location. It doesn't take any arguments while starting. When it is launched in a command window, it displays a help menu with list of commands that can be executed with it and ends with > expecting an input…
Vamsi Emani
  • 10,072
  • 9
  • 44
  • 71
0
votes
1 answer

aapt using Runtime.exec()

I want to run aapt using the Java runtime. My code is as follows: String srcFile = "/home/jay/testing_FILES.apk"; String dsFile = "/home/jay/testing_FILES"; String firstCommand = ("/home/jay/android-sdk-linux/platform-tools/aapt " + "package -u…
JJJ1106
  • 57
  • 2
  • 8
0
votes
2 answers

using android aapt in java program

I have been trying to execute the aapt command through a java program for quite some time now. My hunch is that I should be using the runtime.exec() command to make this happen. However, I have looked at other questions and answers and none seem to…
JJJ1106
  • 57
  • 2
  • 8
0
votes
0 answers

Executing a terminal command in a java progam

javap -classpath /Users/amol/Documents/Java/ -l -c a When I execute the above command in my terminal the output shows the function names in my class along with the local variables Process process3 = Runtime.getRuntime().exec(new String[]{ …
Blood Sport
  • 125
  • 1
  • 2
  • 12
0
votes
3 answers

Compiling C in Java time interval definition

I would like to run in Java with the Runtime's exec() method a C program. The Java code is the following: Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec(command); process.waitFor(); How can I define in this case the compiled…
MMMM
  • 1,319
  • 1
  • 14
  • 32
0
votes
1 answer

Cannot find correct args for rsync to pass to Java Runtime exec to ignore folders

I want to call rsync from Java using Runtime.exec() and I want to ignore hidden files/folders. The command is simple and works like a charm at the command line. rsync -r --exclude=".*" source destination I have tried many, many different…
Peter Kelly
  • 14,253
  • 6
  • 54
  • 63
0
votes
1 answer

exec aapt on Linux by java

I'm finding a way to use Runtime.exec() in Linux. I have an aapt Linux version and trying to get information of apk file with aapt. I tried: rt.exec(new String[] {"bash", "-c","." + new File(".").getCanonicalPath() + "dist/lib/aapt d badging \"" +…
CodeBlue
  • 340
  • 2
  • 4
  • 9
0
votes
4 answers

Alternative to java.lang.Runtime.exec() that can execute command lines as a single string?

I am calling java.lang.Runtime.exec(...) but this seems to accept the command lines as an array and I want to use a single string. How can I do the same using a single string?
sorin
  • 161,544
  • 178
  • 535
  • 806
0
votes
1 answer

Android Runtime.exec("arp") does not work

is there any way to start the command 'arp'. My tries: Runtime rt = Runtime.getRuntime(); proc = rt .exec("arp") -> got an IOException .exec("/proc/net/arp") -> got an IOException as well (found out over the adb shell, that a /proc/net/arp…
Tim Ewald
  • 21
  • 1
  • 3
0
votes
3 answers

Java Runtime.exec() with ssh on Linux Issues

I am trying to start a new process using Runtime.exec(), but my problem lies within using ssh to remote in and then run a java program there. Code: test = "ssh -t username@host java packageName.ClassName portNumber (Other command line args for this…
Jesse Naugher
  • 9,780
  • 1
  • 41
  • 56
0
votes
1 answer

FFMPEG in Java (runtime error)

I want to write a program that converts video into frames using FFMPEG. When I use it on the Ubuntu terminal, it works fine. But when I try to put it into the Java code, it gives me a runtime error. Did I make a mistake in my code below? import…
Eric
  • 401
  • 4
  • 13
  • 21
-1
votes
1 answer

How to lock, shutdown, restart and suspend the pc with runtime.exec in java?

How to lock, shutdown, restart and suspend the pc with runtime.exec in java? I want to make a jar for windows and linux os. I want to lock, shutdown, restart and suspend the pc programmatically. I tried this code. package poweroff; import…
Pradeep
  • 19
  • 1
  • 6
-1
votes
1 answer

How do I kill a remote machines process using java api

If a process is started through java runtime.exec (via ssh) how do you get back to this process to kill it (via ssh)? Is there a way to obtain the PID of the invoked process once started? Is sending "kill" via ssh the only way if a PID is…
Mrshll187
  • 11
  • 1
  • 5