import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test {
public static void main(String[] args) {
Process process = null;
String[] cmd = {"cmd", "/C", "help"};
try {
process = Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
e.printStackTrace();
}
assert process != null;
InputStreamReader reader = new InputStreamReader(process.getInputStream());
BufferedReader bufferedReader = new BufferedReader(reader);
String message;
while (true) {
try {
if ((message = bufferedReader.readLine()) == null) {
break;
}
System.out.println(message);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
打印结果:
�й�ij���������ϸ��Ϣ������� HELP ������
ASSOC ��ʾ�����ļ���չ��������
ATTRIB ��ʾ������ļ����ԡ�
BREAK ���û������չʽ CTRL+C ��顣
BCDEDIT �����������ݿ��е������Կ����������ء�
CACLS ��ʾ�����ļ��ķ��ʿ����б�(ACL)��