java - 如何在同一个 cmd 窗口中多次运行 .jar?
问题描述
我的代码必须运行一个生成一系列字符串的 .jar。我输入我想要运行 .jar 的次数以及每次应用程序运行时生成的字符串数。我可以做到,但每次打开一个新的 CMD 窗口时。如何让它显示在单个窗口中?
我知道这是因为我在循环中创建 cmd.exe 进程,但我尝试了其他代码,但我没有创建 cmd.exe 进程,但我无法让它工作。
谢谢。
public static void main(String args[]) {
Process newpro;
int reps = 0, stri = 0;
String command = "cmd /C start cmd.exe /K java -jar D:\\Documents\\NetBeansProjects\\Array\\dist\\Array.jar";
System.out.println("How many times do you want to launch the app?");
reps = readInt(0, 10);
System.out.println("How many strings do you want to create in each repetition?");
stri = readInt();
for (int i = 0; i < reps; i++) {
try {
newpro = Runtime.getRuntime().exec(command + " " + stri);
} catch (SecurityException ex) {
System.out.println("Error.");
} catch (Exception ex) {
System.out.println("Error: " + ex.toString());
}
}
}
解决方案
推荐阅读
- powershell-4.0 - Get-ChildItem 在脚本中不返回任何项目,但从命令行工作
- android - 从 Workmanager 更新 UI
- php - 如何使用重定向 html 创建 htaccess 并从 url 的最后一个获取参数
- .htaccess - CS 购物车重写供应商 URL
- r - ggplot 或 R 中的算术运算和标记
- javascript - 图表js不同的回调标签
- python - 具有固定种子的 scipy.sparse.linalg.eigsh
- matlab - 带有加权字体的表格或绘图
- javascript - Node.js:全局变量是否在实例之间共享?
- postgresql - 如何获取 Postgres 端口