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

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条)

报告相同问题?