The Artima Developer Community
Sponsored Link

Java Answers Forum
Runtime.getRuntime.exec problem...

2 replies on 1 page. Most recent reply: Nov 26, 2003 10:00 AM by edost

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
edost

Posts: 2
Nickname: edost
Registered: Nov, 2003

Runtime.getRuntime.exec problem... Posted: Nov 21, 2003 6:55 AM
Reply to this message Reply
Advertisement
I am tring following code

Runtime.getRuntime.exec("cmd options file1 file2");

'cmd' is absolute path of any exe file. If this any directory in this path contains space(s) than its not working. e.g

if cmd is c:\temp\sayhello.exe its working but if cmd is
c:\temp dir\sayhello.exe its not giving any output. Why??
Any suggestions.


Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: Runtime.getRuntime.exec problem... Posted: Nov 21, 2003 7:50 AM
Reply to this message Reply
You have to surround the command with quotes, as you would from the commandline (i.e., outside of java) anyway:
public class Executer {
    public static void main(String [] args) throws java.io.IOException {
       Runtime runtime = Runtime.getRuntime();
       // note the escaped double-quotes
       runtime.exec("\"c:\\program files\\textpad 4\\textpad.exe\" new_document.txt");
       //            ^^                                         ^^
    }
}

edost

Posts: 2
Nickname: edost
Registered: Nov, 2003

Re: Runtime.getRuntime.exec problem... Posted: Nov 26, 2003 10:00 AM
Reply to this message Reply
Thx joe,
now i am tring following code. My exe file returns value on standard output, i am tring to read this output through stream. it returns null in variable 'line' only when COMMAND contains any space(s) otherwise works fine. Suggest me on this.

String commandStr = "\"" + COMMAND + "\" " + options + " \"" + firstfile + "\" \"" + secondfile + "\"";
Process process = Runtime.getRuntime().exec(commandStr);
BufferedReader buffReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = buffReader.readLine();

Flat View: This topic has 2 replies on 1 page
Topic: polynomial class Previous Topic   Next Topic Topic: share source codes - JBank

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use