首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Spring Shell中执行命令?

如何在Spring Shell中执行命令?
EN

Stack Overflow用户
提问于 2016-01-27 01:56:25
回答 1查看 745关注 0票数 0

我在Spring Shell中执行命令时遇到了问题。我使用此代码在Raspberry PI上闪烁我的LED,但我在Tomcat的日志中收到一个响应错误。

代码语言:javascript
复制
JLineShellComponent shell;
Bootstrap bootstrap = new Bootstrap();      
shell = bootstrap.getJLineShellComponent();
shell.executeCommand("gpio -g write 17 1");
shell.stop();

日志输出为:

代码语言:javascript
复制
org.springframework.shell.core.SimpleParser commandNotFound
WARNING: Command 'sudo gpio -g write 17 1' not found (for assistance press TAB)

当我使用echo命令时,问题仍然存在。

EN

回答 1

Stack Overflow用户

发布于 2016-06-06 04:12:29

如果你想通过Spring Shell执行一个操作系统命令,你必须在前面加上一个感叹号。

代码语言:javascript
复制
shell.executeCommand("! gpio -g write 17 1");

更好的解决方案是根本不使用Spring Shell

代码语言:javascript
复制
Runtime.getRuntime().exec("gpio -g write 17 1");
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35020591

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档