import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.Scanner;
public class GetCmd { private InputStream is=null;
;
public static void main(String args[]) throws IOException
{
OutputStream os=null;
String command=null;
ProcessBuilder pb=new ProcessBuilder("C://Windows//System32//cmd.exe");
Process p=pb.start();
Scanner s=new Scanner(System.in);
System.out.println("welcome come to my cmd ");
String res=null;
BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
os=p.getOutputStream();
res=br.readLine();
System.out.println(res);
while((res=br.readLine())!= null)
{
System.out.println(res);
}
System.out.println("debug");
}
}运行到while()的时候,程序会卡的那里不动,请教高手。不知道这是不是叫阻塞java进程通信
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.Scanner;
public class GetCmd { private InputStream is=null;
;
public static void main(String args[]) throws IOException
{
OutputStream os=null;
String command=null;
ProcessBuilder pb=new ProcessBuilder("C://Windows//System32//cmd.exe");
Process p=pb.start();
Scanner s=new Scanner(System.in);
System.out.println("welcome come to my cmd ");
String res=null;
BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
os=p.getOutputStream();
res=br.readLine();
System.out.println(res);
while((res=br.readLine())!= null)
{
System.out.println(res);
}
System.out.println("debug");
}
}运行到while()的时候,程序会卡的那里不动,请教高手。不知道这是不是叫阻塞java进程通信
{
System.out.println(res); if (res.equals("exit") ){
break;
} }