使用参数文件作为输入从 Java 执行 linux .sh 文件并将输出写入 .txt 文件
当我尝试在 Linux shell 中运行以下 shell 脚本时,
cd /home/fpalma/Project/resources/yices/linux64bit/
bash
chmod a+x yices
./yices /home/fpalma/Project/out/SMT.ys > /home/fpalma/Project/out/SMT.txt
它正在运行并生成文本文件作为 yices 可执行文件的输出。但是,当我使用代码从 Java 运行相同的 shell 脚本时,
String command = mainGUI.PROJECT_PATH+"resources/"+"yices.sh";
process = Runtime.getRuntime().exec(command);
process.waitFor();
或者
String command = mainGUI.PROJECT_PATH+"resources/"+"yices.sh";
pb = new ProcessBuilder(command);
run = Runtime.getRuntime();
Process p = pb.start();
它也在运行但不退出时,除非我退出 java 编译器本身,否则它不会生成文本输出文件。有什么建议吗???
目标:我的目标是使用输入参数文件从 java 运行可执行文件,然后使用“>”生成输出文本文件操作员。
when I try in the linux shell to run the following shell script,
cd /home/fpalma/Project/resources/yices/linux64bit/
bash
chmod a+x yices
./yices /home/fpalma/Project/out/SMT.ys > /home/fpalma/Project/out/SMT.txt
it is running and generating the text file as output of that yices executable. But when I am running the same shell scripts from Java using the code,
String command = mainGUI.PROJECT_PATH+"resources/"+"yices.sh";
process = Runtime.getRuntime().exec(command);
process.waitFor();
or
String command = mainGUI.PROJECT_PATH+"resources/"+"yices.sh";
pb = new ProcessBuilder(command);
run = Runtime.getRuntime();
Process p = pb.start();
it is also running, but not exiting, and unless I am exiting the java compiler itself, it is not generating the text output file. Any suggestions???
Goal: my goal is to run a executable from java using a input paramater file and generate a output text file afterwards using '>' operator.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的“命令”变量应包含完整的命令,即:
mainGUI.PROJECT_PATH+"resources/"+"yices.sh /home/fpalma/Project/out/SMT.ys > /home/fpalma/Project/out/SMT.txt"
your "command" variable should contain the full command, that is :
mainGUI.PROJECT_PATH+"resources/"+"yices.sh /home/fpalma/Project/out/SMT.ys > /home/fpalma/Project/out/SMT.txt"