从java运行命令提示符? [英] Run command prompt from java?

查看:215
本文介绍了从java运行命令提示符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想从命令提示符运行的东西使用java

Hi i want to run something from command prompt using java

我想要到以下目录 C:\Program Files \\ \\ OpenOffice.org 3 \program\
然后运行
soffice -headless -accept =socket,host = 127.0.0.1,port = 8100; urp; -nofirststartwizard

我试过,但我不能这样做!

i tried but i am not able to do that!

我的代码

public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {
            Runtime rt = Runtime.getRuntime();
            //Process pr = rt.exec("cmd /c dir");

           // Process pr = rt.exec("cmd /c dir");

            Process pr = rt.exec(new String[]{"C:\\Program Files\\OpenOffice.org 3\\program\\soffice", 
                    "-headless",
                    "-accept='socket,host=127.0.0.1,port=8100;urp;'",
                    "-nofirststartwizard"});

            BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));

            String line=null;

            while((line=input.readLine()) != null) {
                System.out.println(line);
            }

            int exitVal = pr.waitFor();
            System.out.println("Exited with error code "+exitVal);

        } catch(Exception e) {
            System.out.println(e.toString());
            e.printStackTrace();
        }
    }


推荐答案

我解决了它

String[] SOFFICE_CMD = { "C:/Program Files/OpenOffice.org 3/program/soffice", "-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager", "-invisible", "-nologo"}; 
        Runtime.getRuntime().exec(SOFFICE_CMD); 

感谢大家支持!!

这篇关于从java运行命令提示符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆