import java.io.OutputStream ; import java.io.InputStream ; import java.io.OutputStreamWriter ; import java.io.InputStreamReader ; import java.io.BufferedReader ; import java.io.BufferedWriter ; import java.io.IOException ; class TestRuntime { public static void main( String[] args ) { Runtime runtime = Runtime.getRuntime() ; try { Process proc = runtime.exec( "dot -Tps" ) ; OutputStream out = proc.getOutputStream() ; InputStream in = proc.getInputStream() ; BufferedWriter writer = new BufferedWriter( new OutputStreamWriter( out ) ) ; writer.write( "digraph { A->B; B ->C ; A->C }" ) ; writer.close() ; BufferedReader reader = new BufferedReader( new InputStreamReader( in ) ) ; String line = null ; while( null != ( line = reader.readLine() ) ) System.out.println( line ) ; } catch( IOException e ) { System.exit(1) ; } } }这里以 dot 为例,向其发送一个 digraph 然后输出为一个 ps 文件。
Thursday, October 21, 2010
启动一个进程管道输入输出
见下面
Labels:
管道
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment