【发布时间】:2011-06-08 05:09:17
【问题描述】:
嗨,我想使用 java 从命令提示符运行一些东西
我想去以下目录C:\Program Files\OpenOffice.org 3\program\
然后运行
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
我试过了,但我做不到!
我的代码
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();
}
}
【问题讨论】:
-
您遇到了什么样的错误? soffice 可能不在您的系统路径中。
-
请发布显示问题行为的最低完整代码,并发布堆栈跟踪。
-
@joekarl 退出,错误代码为 0
-
@jcomeau-ictx na 当我从命令提示符直接运行它时,它就在那里
标签: java command-line