java中exec命令,java - 从Java中运行exec命令需要 bash 吗? - SO中文参考 - www.soinside.com...
日志輸出顯示了運(yùn)行的命令,可以看到其中包括一個(gè) bash 命令。thufir@dur:~/NetBeansProjects/threadedExecTelnet$
thufir@dur:~/NetBeansProjects/threadedExecTelnet$ gradle run
> Task :run
May 19, 2020 12:25:47 P.M. net.bounceme.dur.exec.ExecList execute
INFO: [bash, -c, ls /home/thufir/NetBeansProjects/threadedExecTelnet]
build
build.gradle
gradle
gradlew
gradlew.bat
LICENSE
README.md
settings.gradle
src
BUILD SUCCESSFUL in 859ms
3 actionable tasks: 1 executed, 2 up-to-date
thufir@dur:~/NetBeansProjects/threadedExecTelnet$
雖然我并不太在意那些繁瑣而啰嗦的代碼public void execute() throws IOException {
log.info(listToExec.toString());
String[] arrayToExec = listToExec.toArray(new String[0]);
Process process = Runtime.getRuntime().exec(arrayToExec);
InputStream inputStream = process.getInputStream();
Reader inputStreamReader = new InputStreamReader(inputStream);
try (BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
String line = null;
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
System.out.flush();
}
}
}
但我不明白為什么有時(shí)會(huì)出現(xiàn)這樣的情況: bash 是必需的,其他時(shí)候則不需要。
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的java中exec命令,java - 从Java中运行exec命令需要 bash 吗? - SO中文参考 - www.soinside.com...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql显错注入,SQL注入:显错注入
- 下一篇: 什么是php工作流,什么是工作流?