java - "run a sh file from jsp page code error"

标签 java html linux shell jsp

我的 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 use sh name.sh, assuming that you've got Cygwin 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/

相关文章:

java - 使用JAVA从Oracle数据库读取网络文件

java - 为什么有些语言使用翻转的 Y Axis ?

javascript - 将 jQuery datepicker 分配给 div 元素并获取值

javascript - 如何生成5个不同的随机数?

c - 编译 C(非 C++)OpenCV 代码时出现问题

java - 如何将请求参数映射到struts2中具有不同名称的bean

java - 获取一年中给定月份的第一天的开始时间和最后一天的结束时间的长值

html - 谷歌脚本提供的 HTML 页面上忽略了 autofocus 属性

linux - 奇怪的 RIAK 行为

linux - Debian、Beaglebone、WIFI 接口(interface)可以传出,不能传入