我的 D:\TrinitiApps28\tabimpl\keystore\my_script.sh
中有一个 sh 文件,其代码在 putty 中运行,输出为“hello world”,
我有一个 shellandantscriptrunner.jsp
,我必须在其中调用这个 my_script.sh
文件才能获取 “hello world”
的输出。
我应该添加什么代码,却收到类似 create process error=193, create process error=2, and read all, attempts all but failed
的错误。
最佳答案
您可以在 jsp 页面中使用 java 执行脚本:
try {
Process p = Runtime.getRuntime().exec("D:\\TrinitiApps28\\tabimpl\\keystore\\sh my_script.sh");
p.waitFor();
System.out.println("exit code: " + p.exitValue());
} catch (Exception e) {
System.out.println(e.getMessage());
}
经过一番研究后,同意 Gyro和来自 this answer
You're on Windows
CMD.EXE
. It uses a different syntax to execute commands. You'll need to usesh name.sh
, assuming that you've gotCygwin
or similar installed.To clarify, Windows does not have a built-in utility to support .sh files. To run such, you'll need to install a third-party tool such as Cygwin.
关于java - "run a sh file from jsp page code error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30297462/