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

Calling external .exe in Windows 8

Is it possible that the following code is no longer working when the application is running on windows 8 Runtime.getRuntime().exec("path\\to\\dotexe"); On Windows 7 it used to do the job just fine, but on Windows 8 it just wont run the d*rn…
Jeroen Pleysier
  • 151
  • 1
  • 8
0
votes
1 answer

groovy (java): exec() do not detach from process (Intellij IDEA vs Maven+TestNG)

I have Groovy Maven2 test project with TestNG and Surefire plugin enabled. I want to launch external process (*.cmd file which start some *.exe file) in last test method, finish my tests and left process running after tests. I tried the following…
zubactik
  • 1,297
  • 3
  • 19
  • 34
0
votes
3 answers

Ping function returns that all pinged IP addresses is reachable

I am tring to ping IP addresses from 192.168.1.1 to 192.168.1.254. First I was using I InetAddress class but it was bugged and some IPs where not reachable even if they are. After that I tried this method and it worked very well for single ping IP…
ZhiZha
  • 143
  • 2
  • 4
  • 13
0
votes
1 answer

Using Runtime.getRuntime().exec() to run perl code in java

I have a perl script called pbp that takes an html file as an argument and then creates an output file. Here is my current code. Infile is obtained earlier from a JFile Chooser. I don't get any errors but there is no ouput from the perl script. try…
0
votes
2 answers

Running the Bin file with get.Runtime.exec()?

This the C++ code for hello.exe: #include #include int main() { cout<<"Hello world\n"; getch(); cout<<"I bypass error\n"; return 0; } I need to run hello.exe from a Java program. I want to learn Java in order to call…
0
votes
2 answers

Execute java prog without Runtime.exec()? Does any "JavaExecutor" exist?

Is there any way to run a Java program from inside another Java program without using Runtime exec? Is there some kind of JavaExecutor tool which one could use with a DiagnosticCollector? (Like JavaCompiler)?
Bastien
  • 658
  • 1
  • 9
  • 24
0
votes
1 answer

Using Runtime.exec() with String [ ]

I am trying to execute a bash script that gets passed 4 arguments from java. I can execute the script without the arguments perfectly using this code: try { String command = "bash bash/testbash.sh"; …
Jeff
  • 674
  • 1
  • 5
  • 17
0
votes
2 answers

Not getting any output after calling C executable file from Java code

I am trying to execute the C code from Java code which is already compiled and executed, but, I am not getting any output from the executable file. Can anyone help me to complete this task? Code is as follows. public class Test { public static…
Sankar
  • 162
  • 2
  • 13
0
votes
2 answers

Change content of batch file

How to change content of batch file using Java code? I worked with parsing XML using Java program. It worked fine. But can I do same for the batch file using Java? I am able to run batch file using below code. String command = "cmd /c start " +…
user2215139
  • 1,805
  • 2
  • 18
  • 24
0
votes
1 answer

Restart Unix service

I have Ubuntu in my machine where I have installed snmpd. To start stop I use below command: service snmpd start service snmpd stop Now I have to execute this comments from java. I have tried with but it does not work.…
Souvik
  • 1,219
  • 3
  • 16
  • 38
0
votes
2 answers

Java process.waitFor() does not return

On Windows 7 64 bit, running 64 bit Java 1.7.0_17 , the p.waitFor() shown below never returns. String move_command="cmd.exe /c xcopy /Y /E "+x86_release+" "+path+"\\"; Process p; p = Runtime.getRuntime().exec(move_command); p.waitFor(); If I use…
kmort
  • 2,848
  • 2
  • 32
  • 54
0
votes
3 answers

Pass a string with spaces to an execute command in Java to execute a bash script

How do I pass a string with spaces to an execute command in Java to execute a bash script? I'm trying to use a script to generate and send a email using the unix mail command but it ignores the quotes surrounding the message…
jonnie
  • 12,260
  • 16
  • 54
  • 91
0
votes
1 answer

Unable to run Shell Script

Hi i am trying to run shell script from following code import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class ScriptTest { public static void main(String[] args){ BufferedReader…
Sohail Khan
  • 279
  • 1
  • 3
  • 10
0
votes
2 answers

how to wait for batch command to complete its excecution in java

I want to wait till my batch command completes its execution and creates a CSV file as output. The code is as bellow for executing batch file String command = "cmd /c start " + batFile; Runtime rt = Runtime.getRuntime(); Process pr =…
shravani
  • 17
  • 7
0
votes
2 answers

error when trying to execute exe from Runtime object in java

I am running windows 7 and have an exe file I am trying to run using the following command in Java: File dir = new File("C:\\PATH\\TO\\DIR"); String[] cmdArray = {"file.exe"}; if(dir.exists()){ for(String s : dir.list()){ …
user972276
  • 2,973
  • 9
  • 33
  • 46