Runtime.exec()方法在Spring环境中总是返回空(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); }I tried to execute Runtime.exec(…) method in my Spring application and then always getting empty result from getInputStream() method. But it's working well if I execute as a core java application. Is any other implementations needed to execute in Spring environment? Thanks in advance.
Spring Version : 4.2.1.RELEASE
commons-io Version : 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'Maybe User privileges issues. I'm also worked in the similar type of scenario.
In this case both services should be run as same user(XYZ) Otherwise 'spamc' library files location should be point to your user(XYZ) HOME path '.bashrc' and reset '.bashrc'更多推荐
发布评论