在Spring Shell中运行date命令(“无法运行程序......系统找不到指定的文件”)

时间:2014-02-20 12:39:13

标签: shell spring-shell

根据documentation所说的

  

OsCommands - 此命令的关键字是感叹号后的感叹号    你可以传入要执行的Unix / windows命令字符串

这意味着,我们可以通过在操作系统命令前添加!(感叹号)来在Spring Shell中执行OS命令。

但我相信存在一些问题,或者我遗漏了一些东西。当我尝试时,我得到了以下错误。

hw-shell>! date
command is: date
Unable to execute command date [Cannot run program "date" (in directory "."): CreateProcess error=2, The system cannot find the file specified]

3 个答案:

答案 0 :(得分:0)

我认为您可能忘记在spring shell类中设置类路径,使用下面的行设置类路径然后尝试...

new ClassPathXmlApplicationContext("classpath*:/META-INF/spring/spring-shell-plugin.xml");

更多参考资料:http://docs.spring.io/spring-shell/docs/current/reference/html/shell.html

答案 1 :(得分:0)

根据缺少的异常消息,您是否在Windows的%PATH%环境中实际拥有“date”命令。

答案 2 :(得分:0)

“date”是windows命令shell的内置命令。看起来这些内置命令在spring-shell中是不可用的,而spring-shell会查看在windows路径中作为文件存在的命令。

Windows可以使用非内置的calc(! calc)命令。