开发者社区 问答 正文

java如何通过cmd运行phantomjs

我的phantomjs.exe 在D盘/phantomjs/bin下,现在我要在java里面通过Runtime.getRuntime().exec()来运行这个命令:

phantomjs highcharts-convert.js -host 127.0.0.1 -port 3003
String cmd = "这里改如何写呢";
 String cmd = "";
 Runtime runtime = Runtime.getRuntime();
 runtime.exec(cmd)

展开
收起
蛮大人123 2016-06-06 15:37:04 3084 分享 版权
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪
    public static void main(String[] args) {
            try
    
            {
    
                Process process = Runtime.getRuntime().exec ("ls");
    
                InputStreamReader ir=new InputStreamReader(process.getInputStream());
    
                LineNumberReader input = new LineNumberReader(ir);
    
                String line;
    
                while ((line = input.readLine ()) != null)
    
                    System.out.println(line);
    
            }
    
            catch (java.io.IOException e){
    
                System.err.println ("IOException " + e.getMessage());
    
            }
        }

    这是一个执行ls命令的例子,你在你自己机子上执行一下 你就明白了

    2019-07-17 19:28:46
    赞同 展开评论
问答分类:
问答地址: