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

    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)
    [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: Cannot run program "draw(1,2)": 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
    Blog Entries
    Rep Power


    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 Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

Similar Threads

  1. Commands on java.
    By Slithice in forum New To Java
    Replies: 15
    Last Post: 11-15-2012, 11:06 AM
  2. using RMAN commands in Java
    By mario_tim in forum JDBC
    Replies: 4
    Last Post: 03-22-2011, 05:59 AM
  3. At commands in java
    By strictlydivine.elite in forum Advanced Java
    Replies: 1
    Last Post: 11-22-2010, 10:55 AM
  4. Run Unix commands from Java
    By yahyaaa in forum New To Java
    Replies: 13
    Last Post: 06-18-2010, 12:50 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