Runtime.exec()方法在Spring环境中总是返回空(Runtime.exec() method always returns empty in Spring environment)

编程入门 行业动态 更新时间:2024-10-08 10:54:30
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'

更多推荐

本文发布于:2023-07-27 04:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1284914.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:环境   方法   Spring   Runtime   exec

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!