Java Runtime.Exec() Guide ���� runtime.exec ((������
Everything you ever wanted to know and should know about Java Runtime.exec(). �� �� ��� ���� �� ���� �� �� ��� ��� ���� �� ���� �� ���� runtime.exec ().
This old but still golden ��� ������� ������ �� ���� ������ article ������ is an excellent guide to using Runtime.exec(). ����� ���� ������� runtime.exec (). The key points he discusses are: ������ �������� �� ��� ����� :
1. You need to drain the input stream to prevent because failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock. ��� ����� ��� ������� ������ ���� ���� ��� ����� ��� ������� �� ����� ������ ���� �� ����� ������ ������ �� ����� ���� �� ����� ���� �� ����� �� ����� ����� ���� �� ����� � ���� ��� ���� �����.
2. Use waitFor() instead of exitValue() when you want to wait for the process to finish. ������� waitfor () ���� �� exitvalue ((����� ���� �������� ���� �������� �� �������.
3. Runtime.exec() wouldn't directly execute shell commands like dir / ls, copy / cp etc. You need to invoke the shell cmd.exe / bash / sh and pass the shell commands. Runtime.exec ((�� ������ ����� ������� ��� ��� �� / ���� ����� � ��� / ��� ��������� ��� ��� ����� ��� �������� ��� �� cmd.exe / ������ / � �� ������ �������. For example in windows your command array to execute dir would be as follows: ���� ���� ������ ������ ����� �� �� ����� ������ ������ ��� ����� ��� ��� :
cmd[0] = "cmd.exe" ; CMD [0] = "cmd.exe" �
cmd[1] = "/C" ; CMD [1] = "/ �" �
cmd[2] = "dir"; CMD [2] = "���" �
Personally I have successfully used Runtime.exec() on several occasions. ��� ����� ������� ����� runtime.exec)) �� ��� �������. Any C programmer should quickly find equivalence with fork and system calls in C language. � ����� �� �� ����� ������ ����� ��� ������� �� ������ ����� ������ �� ��� �. As always RTFM. ���� �� ����� ����� rtfm.
Filed under ������ ������ Headline News ��� ������� , � How To ��� , � J2EE ������� , � Java Software ������ ���� , � Programming ������� , � Tech Note ������ ����� | |
| |
RSS 2.0 �� �� �� 2�0 | |
Trackback this Article | ��� ������ |
Email this Article ���� ��� ������
You may also like to read ������ ���� �� ���� |




































June 9th, 2008 at 10:23 pm ������ �� ������ / ����� � 2008 �� ������ 10:23
Hi all , ����� ��� �� ��� �
How to execute the mysql command in linux using the runtime.exec. ����� ����� ����� ������ �� ����� �������� runtime.exec.
example : ���� :
String []cmds_slave1={ ����� [] = (cmds_slave1
“/bin/sh”,”mysql test”, "/ �� / �" � "������ ������" �
}; ) �
p3=Runtime.getRuntime().exec(cmds_slave1); P3 = runtime.getruntime (). ����� (cmds_slave1) �
BufferedReader pr = new BufferedReader(new InputStreamReader(p3.getInputStream())); �������� ������� bufferedreader = bufferedreader ������� (����� inputstreamreader (p3.getinputstream ()))�
System.out.println(”after buFFer stmt”); System.out.println ( "��� stmt �����") �
String x1; ����� x1 �
while ((x1 = pr.readLine()) != null) �� ��� �� ((x1 = pr.readline ())! = ����)
{ (
System.out.println(x1 + ” from mysqllll…”); System.out.println (x1 + "�� mysqllll…") �
} )
}catch(Exception e) �����) (�������� �)
{ (
e.printStackTrace(); e.printstacktrace () �
} )
p3.waitFor(); p3.waitfor () �
But i am not getting any output. ���� ��� �� ������ ��� �� �������.
Please let me know how to proceed more. ������� �� �� ���� ����� ����� ���� ���� �� ���.
Thanks In Advance. ����� ����� �� ��� �����.
Prakash ������