Results 1 to 4 of 4
  1. #1
    Prompt is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default Question about java's Runtime.exec

    The following is the code I am using to run a C++ executable from java :
    Java Code:
     Process p = null;
           String path = "C:/.../Program.exe"; //psuedo-path but I use the actual path
           String args = "3 1 2";
           String cmds[] = {path,args};
           p = Runtime.getRuntime().exec(cmds);      
           doRead(); //read from the inputstream and errorstream
           println("Exit code : " + p.waitFor());
    The problem is that process is just using the first element in args as the actual
    argument and not the whole args value. That is only the value '3' is being used as an argument to the Program.exe.
    I hope i am clear enough. Any help please on how to solve this.

  2. #2
    Prompt is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default

    Solved it thanks.

  3. #3
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    6

    Wink

    Quote Originally Posted by Prompt View Post
    Solved it thanks.
    How? Could you let others know?

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  4. #4
    Prompt is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default

    Sure, the following code solves it :
    Java Code:
     Process p = null;
           String path = "C:/.../Program.exe"; //psuedo-path but I use the actual path
           String cmds[] = {path,"2","4","1"};
           p = Runtime.getRuntime().exec(cmds);      
           doRead(); //read from the inputstream and errorstream
           println("Exit code : " + p.waitFor());
    So each argument needs its own position in the cmds array. In the previous code, the error was because all the arguments were supplied in one array, whereas in the code above, each argument has its own index in the cmds array.

Similar Threads

  1. question with command prompt and Runtime.exec()
    By mosquetero in forum New To Java
    Replies: 3
    Last Post: 08-11-2009, 01:08 PM
  2. runtime.exec
    By cotede2 in forum Advanced Java
    Replies: 3
    Last Post: 04-17-2009, 06:18 PM
  3. help with Runtime.exec()
    By Lanfear in forum New To Java
    Replies: 18
    Last Post: 12-16-2008, 12:09 PM
  4. Runtime.exec()
    By hknyo in forum Advanced Java
    Replies: 2
    Last Post: 08-16-2008, 01:40 AM
  5. Problem with Runtime.exec()
    By nhabibi in forum Advanced Java
    Replies: 11
    Last Post: 07-02-2008, 02:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •