50,523
社区成员
发帖
与我相关
我的任务
分享
@echo on java -cp %1 %2
pause
import java.io.InputStream;
public class CMDTest {
public static void main(String[] args) throws Exception {
CMDTest cmd = new CMDTest();
cmd.excute("dir");
}
private void excute(String action) {
Runtime run = Runtime.getRuntime();
try {
Process process = run.exec("cmd.exe /k start " + action);
InputStream in = process.getInputStream();
while (in.read() != -1) {
System.out.println(in.read());
}
in.close();
process.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
}
}