runtime.exec

Java runtime.exec does not execute correctly

陌路散爱 提交于 2019-11-30 20:45:32
问题 I am getting an exe-File, which I have to execute using Java (Version 6) on Windows Server 2008 R2. Now there is s problem I do not really understand. When executing the file with the commandline "C:\test.exe param1 param2" it works correctly, but when I execute the file with Process proc = Runtime.getRuntime().exec("C:\\test.exe param1 param2"); proc.waitFor(); I can see the test.exe in the windows task manager and it starts running (it creates a log which states that), but then it simply

Process Runtime pass input

时光怂恿深爱的人放手 提交于 2019-11-30 16:13:21
I have rsync command to be run in a java program...the problem i am facing is that rsync requires a password to be entered and i am not understanding how to pass this password to the rsync command to work? Andrei LED I was gonna post this code sample: Process rsyncProc = Runtime.exec ("rsync"); OutputStreanm rsyncStdIn = rsyncProv.getOutputStream (); rsyncStdIn.write ("password".getBytes ()); But Vineet Reynolds was ahead of me. As Vineet Reynolds pointed out using such approach will require an additional piece of code to detect when rsync requires a password. So using an external password

Process Runtime pass input

核能气质少年 提交于 2019-11-30 16:11:18
问题 I have rsync command to be run in a java program...the problem i am facing is that rsync requires a password to be entered and i am not understanding how to pass this password to the rsync command to work? 回答1: I was gonna post this code sample: Process rsyncProc = Runtime.exec ("rsync"); OutputStreanm rsyncStdIn = rsyncProv.getOutputStream (); rsyncStdIn.write ("password".getBytes ()); But Vineet Reynolds was ahead of me. As Vineet Reynolds pointed out using such approach will require an

How to send a command to android and then get its answer?

大兔子大兔子 提交于 2019-11-30 14:25:01
问题 I want to write echo -e "AT\r" > /dev/smd0 in the shell and then get its response. The response will be in \dev\smd0 . I searched Google and found this : Runtime r = Runtime.getRuntime(); process = r.exec("su"); process = r.exec("echo -e \"AT\\r\" > /dev/smd0"); but it does not work. And I do not know how to read the response. If I install Terminal emulator, I can write the command and get its response with cat \dev\smd0 . 回答1: Try like this: try { Runtime r = Runtime.getRuntime(); Process

Java Runtime.getRuntime().exec() fails after calling it several hundred times

空扰寡人 提交于 2019-11-30 10:12:45
I have a Java program that executes Runtime.getRuntime().exec("ls -l"); many times, once for each directory in the system. My test system has more than 1,000 directories and Runtime.getRuntime().exec("ls -l"); seems to error out after 480 directories or so. The error message I'm getting is is "Error running exec(). Command: [ls, -l] Working Directory: null Environment: null". I'm guessing it's running out of some required system resources or is it? Is there any way to process all directories without erroring out? Relative comment from an answer: I should clarify that I was using Android SDK's

Mock Runtime.getRuntime()?

北战南征 提交于 2019-11-30 08:26:46
Can anyone make any suggestions about how best to use EasyMock to expect a call to Runtime.getRuntime().exec(xxx) ? I could move the call into a method in another class that implements an interface, but would rather not in an ideal world. interface RuntimeWrapper { ProcessWrapper execute(String command) throws IOException; } interface ProcessWrapper { int waitFor() throws InterruptedException; } I was wondering if anyone had any other suggestions? Your class shouldn't call Runtime.getRuntime() . it should expect a Runtime to be set as its dependency, and work with it. Then in your test you can

Handle Input using StreamGobbler

拜拜、爱过 提交于 2019-11-30 05:11:39
问题 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

Problem with Runtime.exec and Android

a 夏天 提交于 2019-11-29 16:42:45
I have an issue when I'm using Runtime.exec with my Android device and just can't figure out why it happens... Here is an example of the tests I did : public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Runtime runtime = Runtime.getRuntime(); for(int i=0; i< 20; i++){ Log.d("TESTEXEC", "EXEC N°"+i+" : BEGIN"); try { Process process = runtime.exec("/system/bin/ps"); process.getErrorStream().close(); process.getOutputStream().close(); process.getInputStream().close(); process

Unable using Runtime.exec() to execute shell command “echo” in Android Java code

断了今生、忘了曾经 提交于 2019-11-29 14:07:57
I can use Runtime.exec() to execute shell commands like " getprop " and " ls system " and they work fine. However, when I use " echo $BOOTCLASSPATH ", " echo \\$BOOTCLASSPATH " or " echo HelloWorld ", it won't show it in stdout. The logcat shows: I/AndroidRuntime( 4453): VM exiting with result code -1. Here's my code: try { java.lang.Process proc = Runtime.getRuntime().exec("echo -e \\$BOOTCLASSPATH"); String line = null; InputStream stderr = proc.getErrorStream(); InputStreamReader esr = new InputStreamReader (stderr); BufferedReader ebr = new BufferedReader (esr); while ( (line = ebr

Trying to execute a Java jar with Runtime.getRuntime().exec()

若如初见. 提交于 2019-11-29 12:24:11
In the project I am working on, I need to execute a script that I have in a resources folder -- in the class path. I am simply testing the final script functionality, since I am on Windows, I needed a way to output a file to STDIN so I created a simple cat.jar program to clone unixs cat command. So when I do "java -jar cat.jar someFile.txt" it will output the file to stdout. I'm sure there are different ways of doing what I did. Anyways, I want to run that JAR from my main java program. I am doing Runtime.getRuntime().exec("java -jar C:/cat.jar C:/test.txt"); I've tried switching the forward