0

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

JLineShellComponent shell;
Bootstrap bootstrap = new Bootstrap();      
shell = bootstrap.getJLineShellComponent();
shell.executeCommand("gpio -g write 17 1");
shell.stop();

日志输出为:

org.springframework.shell.core.SimpleParser commandNotFound
WARNING: Command 'sudo gpio -g write 17 1' not found (for assistance press TAB)

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

4

1 回答 1

1

如果要通过 Spring Shell 执行 OS 命令,则必须在前面加上感叹号。

shell.executeCommand("! gpio -g write 17 1");

更好的解决方案是完全不使用 Spring Shell

Runtime.getRuntime().exec("gpio -g write 17 1");
于 2016-06-05T20:12:29.240 回答