Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java getRuntime().exec()不工作_Java_Ubuntu 14.04_Shellexecute - Fatal编程技术网

java getRuntime().exec()不工作

java getRuntime().exec()不工作,java,ubuntu-14.04,shellexecute,Java,Ubuntu 14.04,Shellexecute,我正在尝试使用JavaExec来运行我的脚本,得到结果并在我的程序中使用它 我有以下几行代码 public static void main(String[] argv) throws Exception { Process p = Runtime.getRuntime().exec("phantomjs quebecPhantom.js"); BufferedReader in = new BufferedReader(new InputStreamReader(p.get

我正在尝试使用JavaExec来运行我的脚本,得到结果并在我的程序中使用它

我有以下几行代码

public static void main(String[] argv) throws Exception {

    Process p = Runtime.getRuntime().exec("phantomjs quebecPhantom.js");

    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));

    String line = in.readLine();

    System.out.println(" [x] Sent '" + line + "'");
}
我希望我的PhantomJS脚本能够被执行,而line变量将获取脚本的输出。但是,我的脚本没有执行,它应该需要更多的时间,它应该会产生一些我看不到的屏幕截图。然后,line变量接受空值


我应该考虑更多的东西来执行我的脚本吗?< /P> < P>上面代码行的问题是,我需要得到幻像的路径,也需要我要执行的命令中的脚本。那么这条线应该改变如下

Process p = Runtime.getRuntime().exec("path to phantomjs" + " " + "path to the script");
在我的情况下是这样的

Process p = Runtime.getRuntime().exec("/usr/bin/phantomjs /home/name/quebecPhantom.js");

quebecPhantom.js的路径正确吗?phantomjs的路径正确吗?commons exec:phantomjs的脚本与我的java代码所在的目录相同。我应该为这条路做些特别的事吗?