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

How can I start a second Java process?

How can I start a second Java process platform independent? Ideally it should be the same Java version that currently running. Are there any helpful system properties?
Horcrux7
  • 23,758
  • 21
  • 98
  • 156
8
votes
2 answers

Run a sub process, provide input and output to it correctly in Java

I use Runtime exec() method to create a subprocess in Java. However, since the subprocess is an interactive program, I need to provide input to it as and when required by it. Also I need to show the output of the subprocess. How can I do this in the…
SkypeMeSM
  • 3,197
  • 8
  • 43
  • 61
8
votes
5 answers

Runtime.getRuntime().exec()

I can not read a file only when database name contains like (new database (myid) etc. I give a following example code: dumpCommand = "C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump -h"+hostName+user+databaseName; Runtime rt =…
JohnRaja
  • 2,377
  • 6
  • 26
  • 47
8
votes
2 answers

Python GUI from Java

I am working on a program which takes a user input and generates an output as a map projection plot. The easiest map projection library that I have found is matplotlib-basemap, written in python a language I am not much familier with (I work on Java…
javaEd
  • 158
  • 2
  • 10
8
votes
3 answers

How do I run command line from Java code in the background?

I have the following line to run a batch file, Process process = Runtime.getRuntime().exec("cmd /c start rake.bat"); But I want it to run in the background and not display the command line to the user. How can I change it to do this? The problem…
cHam
  • 2,624
  • 7
  • 26
  • 28
7
votes
4 answers

How to execute a interactive shell script using java Runtime?

I am wondering is there any way to execute following shell script, which waits for user input using java's Runtime class? #!/bin/bash echo "Please enter your name:" read name echo "Welcome $name" I am using following java code to do this task but…
Rahul Borkar
  • 2,742
  • 3
  • 24
  • 38
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
2 answers

Terminate process run with `exec` when program terminates

I have a java program that runs another (Python) program as a process. Process p = Runtime.getRuntime().exec("program.py", envp); If the java program finish processing, the Python process is finished as well. The finish command sends a signal to…
czuk
  • 6,218
  • 10
  • 36
  • 47
7
votes
7 answers

How to kill subprocesses of a Java process?

I am creating a process P1 by using Process P1= Runtime.exec(...). My process P1 is creating another process say P2, P3.... Then I want to kill process P1 and all the processes created by P1 i.e. P2, P3... P1.destroy() is killing P1 only, not its…
vermap
  • 71
  • 1
  • 2
7
votes
7 answers

How to open the notepad file in java?

I want to open Notepad in my Java program. Suppose that I have one button if I click this button the notepad will appear. I already have a file name and a directory. How can I implement this case?
guilgamos
  • 1,695
  • 4
  • 13
  • 5
7
votes
4 answers

FileNotFoundException when using java properties file

am asking this question after doing a lot of research and also implementing it in my code after the research but I ended up with FileNotFoundException.What exactly am doing here is I want to avoid hardcoding in my java code so am creating a…
user2821894
  • 988
  • 2
  • 11
  • 20
7
votes
6 answers

Java Runtime Exec on Windows Fails with Unicode in Arguments

I want to launch a browser and load a web page using Java's Runtime exec. The exact call looks like this: String[] explorer = {"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE", "-noframemerging", "C:\\ ... path containing unicode chars…
Bear
  • 201
  • 1
  • 3
  • 7
7
votes
1 answer

Handle Input using StreamGobbler

I have been through the StreamGobbler and I understand the usage and the reason on why it has been implemented. However the scenarios covered are only those wherein there could be an output from the command / handling errors. I do not find any…
Vivek
  • 2,091
  • 11
  • 46
  • 61
7
votes
1 answer

Java Runtime exec throws no such file or permission denied

My program is running on ubuntu 10.04 ,and here is the code : Process process=Runtime.getRuntime().exec("ls",null,null); it throw an exception of : Cannot run program "ls": java.io.IOException: error=2, No such file or directory, and i tried to…
libing
  • 73
  • 1
  • 3
6
votes
5 answers

Java Runtime.exec() asynchronous output

I'd like to get the output from a long running shell command as it is available instead of waiting for the command to complete. My code is run in a new thread Process proc = Runtime.getRuntime().exec("/opt/bin/longRunning"); InputStream in =…
wmarbut
  • 4,595
  • 7
  • 42
  • 72