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. 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. 2 。 Use waitFor() instead of exitValue() when you want to wait for the process to finish.使用waitfor ( )の代わりにexitvalue ( )したい場合には、処理が完了するまで待つことです。
3. 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 ( )はないのようなシェルコマンドを直接実行するディレクトリ/ lsのは、コピー/ cp等のシェルを起動する必要がありますにcmd.exe / bashを/ shと通過するシェルコマンドです。 For example in windows your command array to execute dir would be as follows:たとえばWindowsのお客様のコマンドを実行するディレクトリの配列は以下のとおり:
cmd[0] = “cmd.exe” ; cmd [ 0 ] = " cmd.exeで" ;
cmd[1] = “/C” ; cmd [ 1 ] = " / c "と;
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.任意のCプログラマーズ等価性とフォークをすばやく見つける必要システムコールにはC言語です。 As always RTFM.いつもrtfmです。
Filed under提出されて Headline Newsニュースの見出し , 、 How Toどのように , 、 J2EE J2EEの , 、 Java Software Javaソフトウェア , 、 Programmingプログラミング , 、 Tech Note技術のノート | |
| |
RSS 2.0 RSS 2.0を | |
Trackbackトラックバック this Article |この記事|
Email this Article電子メールこの記事
You may also like to readを読むようにすることも可能 |




June 9th, 2008 at 10:23 pm 2008年6月9日10:23 pmの
Hi all ,こんにちはすべて、
How to execute the mysql command in linux using the runtime.exec. mysqlコマンドを実行してどのようにLinuxを使用してruntime.execです。
example :例:
String []cmds_slave1={文字列[ ] cmds_slave1 = (
“/bin/sh”,”mysql test”, " / bin / shを" 、 " MySQLのテスト" 、
}; ) ;
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 ( ) ) ! = nullが)
{ (
System.out.println(x1 + ” from mysqllll…”); system.out.println ( x1本+ "からmysqllll … " ) ;
} )
}catch(Exception e)生成) catch (例外メール)
{ (
e.printStackTrace(); 5 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のprakash