Results 1 to 13 of 13
  1. #1
    Join Date
    Jul 2011
    Posts
    6
    Rep Power
    0

    Default how to launch and work within an external software using java

    hello. I am new to java and using eclipse IDE. i have a software known as QEMU which work only on command line i.e no gui and we have to work in this software from command line

    e.g i write this line "qemu-system-arm.exe -M realview-eb -kernel D:\test.out -serial file:test.out" on command line its works fine.

    now i have to lanch this command using java.
    here is my code


    import java.util.*;
    import java.io.*;
    public class Command{


    public static void main(String args[])
    {
    try {
    String fileName = "C:\\Documents and Settings\\Ali\\Desktop\\qemu-0.13.0-arm-win32\\qemu-system-arm.exe";
    String[] commands = {"cmd.exe","/c","start","-M -realview-eb-kernal",fileName};
    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec(fileName);


    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();
    }
    }
    }


    but it didn't work
    Last edited by qwertyuiop415263; 07-12-2011 at 09:53 PM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default

    it didn't work
    Was there anything written to the error stream?

    What is the purpose of the commands String array?

  3. #3
    Join Date
    Jul 2011
    Posts
    6
    Rep Power
    0

    Default

    sorry it should be

    Process pr = rt.exec(commands);
    there is no compile time error

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default

    Hard to debug code that is not what you are executing.

    Was there anything written to the process's error stream?

  5. #5
    Join Date
    Jul 2011
    Posts
    6
    Rep Power
    0

    Default

    i only want to know how to launch a software(no gui) on command line and how to work within that software? (using java).

    only help me with these lines
    how to use .exec command??

    String fileName = "C:\\Documents and Settings\\Ali\\Desktop\\qemu-0.13.0-arm-win32\\qemu-system-arm.exe";
    String[] commands = {"cmd.exe","/c","start","-M -realview-eb-kernal",fileName};
    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec(fileName);

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Google "pitfalls of Runtime.exec". Your problem(s) may already be explained.

  7. #7
    Join Date
    Jul 2011
    Posts
    6
    Rep Power
    0

    Default

    thankx for replying..
    i have already search with this key word but didn't find any useful link. actullay online tutorials only teach how to lanch softwares using java but they dont give any information about how work in these software while residing in the commnd line.

    any help will be appreciated

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    What do you mean by "work in these software"?

    Are you saying that you want a Java app to launch another app such as Word and interact with it? Then I have to ask why? There is the Apache libraries that allow you to read/write Word docs, Excel spreadsheets but there is no need to actually launch Word or Excel.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

  10. #10
    Join Date
    Jul 2011
    Posts
    6
    Rep Power
    0

    Default

    YES exactly .
    because the software i am using "QEMU" works only in command line. when i write qemu-system-arm.exe i enter in the qemu command line.

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default

    You are not responding to this question:
    Was there anything written to the process's error stream?

    Also what is commands used for in your code:

    String[] commands = {"cmd.exe","/c","start","-M -realview-eb-kernal",fileName};
    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec(fileName);

  12. #12
    Join Date
    Jul 2011
    Posts
    6
    Rep Power
    0

    Default

    there is no error written in the error stream.

    it should be
    Process pr = rt.exec(commands);
    instead of
    Process pr = rt.exec(fileName);

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default

    To make sure your code and classes are correct, try using another command.
    Try using it several ways, including some that will cause the command to write to the error stream. This will validate that your code is working correctly.

Similar Threads

  1. Replies: 0
    Last Post: 12-21-2010, 04:21 PM
  2. Replies: 0
    Last Post: 06-19-2010, 09:11 PM
  3. Replies: 0
    Last Post: 03-27-2010, 12:21 PM
  4. Launch External Console app
    By msanders in forum New To Java
    Replies: 2
    Last Post: 12-21-2009, 04:22 PM
  5. How I launch an external program and kill the father?
    By Dr_Misterio in forum New To Java
    Replies: 2
    Last Post: 08-05-2009, 04:31 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
  •