Runtime.exec() 方法在 Spring 环境中总是 returns 空
Runtime.exec() method always returns empty in Spring environment
我试图在我的 Spring 应用程序中执行 Runtime.exec(…)
方法,然后总是从 getInputStream()
方法中得到空结果。但如果我作为核心 java 应用程序执行,它运行良好。在 Spring 环境中是否需要执行任何其他实现?提前致谢。
Spring 版本:4.2.1.RELEASE
commons-io 版本:2.4
try {
Process p = Runtime.getRuntime().exec(new String[] {"sh", "-c", "spamc < abcd.txt"});
String spamResponsexx = IOUtils.toString(p.getInputStream());
log.debug("Spam Response : " + spamResponsexx);
} catch (Exception e) {
e.printStackTrace();
log.error("", e);
}
可能是用户权限问题。我也在类似的场景中工作过。
- 在这种情况下,两种服务都应 运行 作为同一用户 (XYZ)
- 否则 'spamc' 库文件位置应指向您的用户 (XYZ) HOME 路径 '.bashrc' 并重置 '.bashrc'
我试图在我的 Spring 应用程序中执行 Runtime.exec(…)
方法,然后总是从 getInputStream()
方法中得到空结果。但如果我作为核心 java 应用程序执行,它运行良好。在 Spring 环境中是否需要执行任何其他实现?提前致谢。
Spring 版本:4.2.1.RELEASE
commons-io 版本:2.4
try { Process p = Runtime.getRuntime().exec(new String[] {"sh", "-c", "spamc < abcd.txt"}); String spamResponsexx = IOUtils.toString(p.getInputStream()); log.debug("Spam Response : " + spamResponsexx); } catch (Exception e) { e.printStackTrace(); log.error("", e); }
可能是用户权限问题。我也在类似的场景中工作过。
- 在这种情况下,两种服务都应 运行 作为同一用户 (XYZ)
- 否则 'spamc' 库文件位置应指向您的用户 (XYZ) HOME 路径 '.bashrc' 并重置 '.bashrc'