如何从 java 程序打开 IE
How to open IE from a java program
嘿,我试图从 java 程序打开 IE。
命令 start iexplorer
适用于命令提示符和终端,但在 java 程序中使用时会抛出 IOException。当我执行命令 cmd start iexplorer
时,程序只是 运行 而没有停止将近 15 分钟
String command = "cmd start iexplore";
try {
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
这是来自 VScode 的调用堆栈:
image
有人可以帮我解决这个问题
您所做的只是在后台 运行“cmd”。如果 iexplore 在您的系统路径上,那么这可能有效:
String[] cmd = new String[] {"cmd", "/c", "start iexplore"};
“/c”选项告诉 CMD.EXE 启动进程,然后 CMD 立即退出 [在您的情况下,它正在等待更多输入]。您还需要读取进程的 STDERR 流以查看来自 CMD 的任何错误消息。
嘿,我试图从 java 程序打开 IE。
命令 start iexplorer
适用于命令提示符和终端,但在 java 程序中使用时会抛出 IOException。当我执行命令 cmd start iexplorer
时,程序只是 运行 而没有停止将近 15 分钟
String command = "cmd start iexplore";
try {
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
这是来自 VScode 的调用堆栈: image
有人可以帮我解决这个问题
您所做的只是在后台 运行“cmd”。如果 iexplore 在您的系统路径上,那么这可能有效:
String[] cmd = new String[] {"cmd", "/c", "start iexplore"};
“/c”选项告诉 CMD.EXE 启动进程,然后 CMD 立即退出 [在您的情况下,它正在等待更多输入]。您还需要读取进程的 STDERR 流以查看来自 CMD 的任何错误消息。