2009-02-02 5 views

답변

8

사용 ProcessBuilder

예 : 내가 전에 ProcessBuilder를 클래스에 들어하지 않았다

ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2"); 
Process p = pb.start(); 
InputStream in = p.getInputStream(); 
OutputStream out = p.getOutputStream(); 


// Write to input of the program using outputstream here 
... 

// Read output of program from input stream here 
// ... 


FileOutputStream fileOut = new FileOutputStream("output.txt"); 
BufferedInputStream bIn = new BufferedInputStream(in); 

byte buf = new byte[4096]; 
int count; 

while ((count = bIn.read(buf)) != -1) { 
    fileOut.write(buf, 0, count); 
} 

... 
fileOut.close(); 
bIn.close(); 

// Exception handling is left as an exercise for the reader :-P 
+0

. 팁 고마워! –

관련 문제