简体   繁体   中英

Run the date command in Spring Shell (“Cannot run program … the system cannot find the file specified”)

As per the documentation which says

OsCommands - the keyword for this command is the exclamation point, after the exclamation point you can pass in a Unix/windows command string to be executed

This means, we can execute OS commands in Spring Shell by prefixing the OS command with ! (exclamation).

But I believe there is some issue or I am missing something. When I tried, I got the below error.

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]

I thinks you may be forgot to set class path in your spring shell class,Set the class path using below line then try...

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

For More Reference: http://docs.spring.io/spring-shell/docs/current/reference/html/shell.html

根据异常消息的缺失,您是否在Windows的%PATH%环境中真正拥有了“日期”命令。

"date" is a built-in command of the windows command shell. It seems that these built-in commands are not available within spring-shell and spring-shell looks after commands which exist real as file in the windows path.

Windows-Commands like calc ( ! calc ) which are not built-in are available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM