Java-Runtime.getRuntime().exec()发生了什么事? [英] Java - Runtime.getRuntime().exec() what's going on?
本文介绍了Java-Runtime.getRuntime().exec()发生了什么事?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Java中遇到Runtime.exec()问题 我的代码:
I have problem with Runtime.exec() in Java My code:
String lol = "/home/pc/example.txt";
String[] b = {"touch", lol};
try {
Runtime.getRuntime().exec(b);
} catch(Exception ex) {
doSomething(ex);
}
它工作正常,但是当我尝试在硬盘上不创建changle变量"lol"文件时
It's working good but when I trying changle variable "lol" files doesn't create in hard disk
例如:
String lol = x.getPath();
其中getPath()返回String
for instance:
String lol = x.getPath();
where getPath() returns String
我该怎么办?
感谢您的回复:)
推荐答案
这是您解决问题的方法.我遇到了类似的问题,这通过指定输出目录而对我有用,它应该在该工作目录中执行文件的输出.
Here is the solution to your problem . I faced a similar problem and this worked for me by specefying the output directory, it should execute the output of your files in that working directory.
ProcessBuilder proc = new ProcessBuilder("<YOUR_DIRECTORY_PATH>" + "abc.exe"); // <your executable path>
proc.redirectOutput(ProcessBuilder.Redirect.INHERIT); //
proc.directory(fi); // fi = your output directory
proc.start();
这篇关于Java-Runtime.getRuntime().exec()发生了什么事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文