Results 1 to 3 of 3
  1. #1
    talent is offline Member
    Join Date
    May 2011
    Posts
    1
    Rep Power
    0

    Default Run commands in a Java class

    I am trying to run a program by command in a Java class. This program has a specific commands which I would like to execute in a Java program. Running this program in the command line would be as follow:

    [user@mycomputer ~] xx
    xx> draw(1,2)
    ....
    ...
    ...
    xx>end()
    [user@mycomputer ~]

    I tried to do the following:

    Java Code:
    Process child = Runtime.getRuntime().exec("xx");  
    int returnCode = child.waitFor();  
    System.out.println("Return code = " + returnCode);  
      
    child = Runtime.getRuntime().exec("draw(1,2)");  
    returnCode = child.waitFor();  
    System.out.println("Return code = " + returnCode);
    but it gave me the following error:

    java.io.IOException: Cannot run program "draw(1,2)": java.io.IOException: error=2, No such file or directory

    It seems that what this code did is equivalent to the following in the command line:
    [user@mycomputer ~] xx
    [user@mycomputer ~] draw(1,2)

    It is supposed that draw(1,2) is executed under the program xx.

    Any help would be appreciated.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    No idea if this would work, but what if you tried to pass the other commands through the process's output stream obtained via the Process method, getOutputStream(). If you haven't done so, be sure that you read this article: When Runtime Exec Won't

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,251
    Rep Power
    19

Similar Threads

  1. Commands on java.
    By Slithice in forum New To Java
    Replies: 15
    Last Post: 11-15-2012, 10:06 AM
  2. using RMAN commands in Java
    By mario_tim in forum JDBC
    Replies: 4
    Last Post: 03-22-2011, 04:59 AM
  3. At commands in java
    By strictlydivine.elite in forum Advanced Java
    Replies: 1
    Last Post: 11-22-2010, 09:55 AM
  4. Run Unix commands from Java
    By yahyaaa in forum New To Java
    Replies: 13
    Last Post: 06-17-2010, 11:50 PM

Posting Permissions

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