xindongyinfu 2010-12-27 12:50
浏览 184
已采纳

jsp里调用sh文件是否可以调

我在我的jsp里写了这样一句
java.lang.Runtime.getRuntime().exec(path+"ts.sh");
是不是就调用了这个ts。sh脚本文件

试了一下发现报
cannot execute

  • 写回答

9条回答 默认 最新

  • iteye_7064 2010-12-28 10:25
    关注

    [quote]引用
    看看api
    java.lang.Runtime.getRuntime().exec(" ");

    Executes the specified string command in a separate process.

    里面执行的是命令,不是指定文件名。

    exec的参数可以是文件名的
    Java代码
    Runtime.getRuntime()

    .exec("C:\Program Files\Mozilla Firefox\firefox.exe");

    直接打开可执行程序
    在Linux下,可以指定执行的shell脚本,如
    Java代码
    Runtime.getRuntime().exec("test.sh");

    不过我是在SSH终端下执行的,没看到test.sh中执行的效果。[/quote]

    这个是api文档,exec接受的是一条命令
    你的这条语句也是执行的一条命令而已
    Runtime.getRuntime()

    .exec("C:\Program Files\Mozilla Firefox\firefox.exe");

    Process java.lang.Runtime.exec(String command) throws IOException

    Executes the specified string command in a separate process.

    This is a convenience method. An invocation of the form exec(command) behaves in exactly the same way as the invocation exec(command, null, null).

    Parameters:
    command a specified system command.
    Returns:
    A new Process object for managing the subprocess

    理论上只要在命令行里面能执行的命令,exec应该都是可以执行的。
    那个sh文件,可能用sh test.sh或者./test.sh能执行,我没有试。
    返回一个Process类型的变量,可以对其操作。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(8条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器