问题描述如下:
String[] commands = new String[]{"sh","-c","dmidecode -t processor | grep 'ID'"}; Process process = Runtime.getRuntime().exec (commands); InputStreamReader ir = new InputStreamReader(process.getInputStream()); InputStreamReader ir2 = new InputStreamReader(process.getErrorStream()); BufferedReader input = new BufferedReader (ir); BufferedReader input2 = new BufferedReader (ir2); String line,result=""; while ((line = input.readLine ()) != null) { result+=line; } String line2,result2=""; while ((line2 = input2.readLine ()) != null) { result2+=line2; }
0.部署环境为 oracle linux
1.当tomcat正常启动运行的情况下调用可以正常获取到 result的值。
2.当tomcat被crontab的重启任务重启以后无法获取到result值(有时候能获取到),为空,错误信息result2="sh: dmidecode: command not found"
3.人工root权限通过tomcat/bin 目录下的 ./shutdown.sh + ./start.sh 重启以后是能够正常获取的。
4.
初步怀疑是权限问题。crontab的任务是root权限下建立的。
谢谢博主,真是这样,我纠结了好久.你这么牛,请问你是怎么发现的,.