Hi i want to run something from command prompt using java
i want to go to the following directory C:\Program Files\OpenOffice.org 3\program\
and then run
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
i tried but i am not able to do that!
my code
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();
}
}
Don't use cd
, and use the string array method:
rt.exec(new String[]{"C:\\Program Files\\OpenOffice.org 3\\program\\soffice.exe",
"-headless",
"-accept='socket,host=127.0.0.1,port=8100;urp;'",
"-nofirststartwizard"});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With