kun*_*wan 3 java runtime exec runtime.exec
我在Java中的Runtime.exec()问题我的代码:
String lol = "/home/pc/example.txt";
String[] b = {"touch", lol};
try {
Runtime.getRuntime().exec(b);
} catch(Exception ex) {
doSomething(ex);
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,但当我尝试变换变量"lol"文件不会在硬盘中创建
例如:
String lol = x.getPath();getPath()返回String
我该怎么办 ?
感谢您的回复 :)
这是您的问题的解决方案.我遇到了类似的问题,通过对输出目录进行拼写,这对我有用,它应该在该工作目录中执行文件的输出.
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();
Run Code Online (Sandbox Code Playgroud)