runtime.exec

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

寵の児 提交于 2019-12-01 06:38:18
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 can write this: love testgame To run the 'Love' game engine on a folder called testgame. Now, the reason this works is because I've aliased 'love' to call the love executable. I have a feeling that this is the reason that the following does not work: String[] cmd = {"love", "/Users/mtc06/testgame"}; Runtime.getRuntime().exec(cmd); And nor does this

Runtime.getRunTime().exec not behaving like C language “system()” command

空扰寡人 提交于 2019-12-01 06:26:02
In "C", I can run a long blocking process in the background (AND HAVE IT CONTINUE TO RUN) after the starting process has exited. void main(void) { system("some_long_blocking_process &"); exit(); } // "some_long_blocking_process" is still running here (DESIRED BEHAVIOR) Java's getRuntime().exec() DOESN'T have this behavior. Instead, "some_long_blocking_process" ends immediately when the Java process ends. Anyone know how I can recapture this behavior in Java? I am using Java 1.4 (No process builder) I specifically am looking to start the long blocking process and to exit immediately (no

In java determine if a process created using Runtime environment has finished execution?

非 Y 不嫁゛ 提交于 2019-12-01 06:08:07
Runtime.getRuntime.exex("abc.exe -parameters"); using .waitFor() does not help to determine the completion of process. Process.waitFor() ( javadoc ) should work. If it doesn't work then either: there's a bug in the JVM or the OS ( highly unlikely for something like this), or there is something about the process and/or your Java code that means that the process won't exit. In current releases of Java you can also use Process.isAlive ( javadoc ) to test the process status without blocking until it finishes. For Java 7 and older there is a hacky solution that entails polling the process return

Android Runtime.getRuntime().exec() to nav through directories

萝らか妹 提交于 2019-12-01 05:12:45
So I want to be able to write an app that can turn on and display logcat messages, dmesg, and also be able to run commands like 'ls' 'cat' 'echo' 'cd.' If I do the following: nativeProc = Runtime.getRuntime().exec("ls\n"); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(nativeProc.getOutputStream())); BufferedReader in = new BufferedReader(new InputStreamReader(nativeProc.getInputStream())); String line = null; while ((line = in.readLine()) != null) { full = full + "\n" + line; } I can put the text "full" to a Text View and see the root directory. However, that's about all I can

Runtime.getRunTime().exec not behaving like C language “system()” command

╄→尐↘猪︶ㄣ 提交于 2019-12-01 04:56:52
问题 In "C", I can run a long blocking process in the background (AND HAVE IT CONTINUE TO RUN) after the starting process has exited. void main(void) { system("some_long_blocking_process &"); exit(); } // "some_long_blocking_process" is still running here (DESIRED BEHAVIOR) Java's getRuntime().exec() DOESN'T have this behavior. Instead, "some_long_blocking_process" ends immediately when the Java process ends. Anyone know how I can recapture this behavior in Java? I am using Java 1.4 (No process

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

爱⌒轻易说出口 提交于 2019-12-01 03:38:59
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, pdfPathOut}; Process proc = Runtime.getRuntime().exec( cmd, null ); proc.waitFor(); But waitFor() never returns. I can still see the process in the Windows Task Manager (with the command line I passed to exec(): looks fine). AND IT WORKS. wkhtmltopdf produces the PDF I'd expect, right where I'd expect it. I can open it, rename it, whatever, even while the

In java determine if a process created using Runtime environment has finished execution?

爷,独闯天下 提交于 2019-12-01 03:26:25
问题 Runtime.getRuntime.exex("abc.exe -parameters"); using .waitFor() does not help to determine the completion of process. 回答1: Process.waitFor() (javadoc) should work. If it doesn't work then either: there's a bug in the JVM or the OS ( highly unlikely for something like this), or there is something about the process and/or your Java code that means that the process won't exit. In current releases of Java you can also use Process.isAlive (javadoc) to test the process status without blocking

Android Runtime.getRuntime().exec() to nav through directories

折月煮酒 提交于 2019-12-01 03:24:54
问题 So I want to be able to write an app that can turn on and display logcat messages, dmesg, and also be able to run commands like 'ls' 'cat' 'echo' 'cd.' If I do the following: nativeProc = Runtime.getRuntime().exec("ls\n"); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(nativeProc.getOutputStream())); BufferedReader in = new BufferedReader(new InputStreamReader(nativeProc.getInputStream())); String line = null; while ((line = in.readLine()) != null) { full = full + "\n" + line;

Get output of cmd command from java code

拥有回忆 提交于 2019-11-30 21:22:16
I have a program where I was able to successfully execute cmd commands from my code, but I want to be able to get the output from the cmd command. How can I do that? So far my code is: Second.java: public class Second { public static void main(String[] args) { System.out.println("Hello world from Second.java"); } } and Main.java public class Main { public static void main(String[] args) { String filename = args[1].substring(0, args[1].length() - 5); String cmd1 = "javac " + args[1]; String cmd2 = "java " + filename; Runtime r = Runtime.getRuntime(); Process p = r.exec(cmd1); // i can verify

Handle Input using StreamGobbler

风格不统一 提交于 2019-11-30 20:53:17
I have been through the StreamGobbler at the following URL JavaWorld : Stream Gobbler 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 error's. I do not find any scenario wherein StreamGobbler is used to handle inputs. For example, in mailx , I have to specify the body of the email, which I have done in the following format Process proc = Runtime.getRuntime().exec(cmd); OutputStreamWriter osw = new OutputStreamWriter(proc.getOutputStream()); osw.write(mailBody); osw