【发布时间】:2014-10-07 05:16:39
【问题描述】:
我正在尝试在 java 代码中运行 linux 命令。该命令是 raspivid ,我已将它放在服务器上的 test.sh 文件中,用于实时摄像头流式传输。一切正常,但问题是在启动 tomcat 服务器几分钟后流停止。就像在 java 中运行命令时流式传输在 6-7 分钟后停止一样,但在后台运行 raspivid 进程。另一方面,当我在不使用 java 代码的情况下运行相同的命令时,它工作正常。这是tomcat堆的问题还是其他停止流式传输的问题?请帮忙看看下面的代码:
try {
Process p = Runtime.getRuntime().exec(new String[]{"sudo","sh","/home/pi/test.sh"});
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
LOGGER.info("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
LOGGER.info(s);
}
// read any errors from the attempted command
LOGGER.info("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
LOGGER.info(s);
}
}
【问题讨论】:
标签: java linux tomcat debian raspberry-pi