Cmd Prompt qustion

Discussion in 'Java' started by Chris, Jan 3, 2009.

  1. Chris

    Chris Guest

    All,
    I am looking to interact with the command prompt on my Windows XP
    (sp2) system. I have reread books and followed message board threads
    and have found success in executing cmd.exe and loading up a batch
    file.
    However, now that the batch has loaded and I can see it, I am trying
    to interact with it through my java project. (By intereact I mean pass
    arguments and text to it). Here's where I get stuck... Does anyone
    know how I can accomplish this?

    Thank you very much for your time.
    *****************************************************************
    import java.io.*;

    public class ArConsole {

    public static void main(String args[])
    {
    try

    {
    String intel = "C://arconsole.bat";

    Runtime rt = Runtime.getRuntime();

    Process pr = rt.exec(intel);

    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();
    }
    }
    }
    Chris, Jan 3, 2009
    #1
    1. Advertising

  2. Chris

    Arne Vajhøj Guest

    Chris wrote:
    > All,
    > I am looking to interact with the command prompt on my Windows XP
    > (sp2) system. I have reread books and followed message board threads
    > and have found success in executing cmd.exe and loading up a batch
    > file.
    > However, now that the batch has loaded and I can see it, I am trying
    > to interact with it through my java project. (By intereact I mean pass
    > arguments and text to it). Here's where I get stuck... Does anyone
    > know how I can accomplish this?


    > String intel = "C://arconsole.bat";
    >
    > Runtime rt = Runtime.getRuntime();
    >
    > Process pr = rt.exec(intel);


    For passing command line args I would try:

    String[] intel = { "cmd", "/c", "C:\\arconsole.bat", "foo", "bar" };
    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec(intel);

    And I would give up trying to make real interaction with the
    app being run.

    Arne
    Arne Vajhøj, Jan 3, 2009
    #2
    1. Advertising

  3. Chris

    Roedy Green Guest

    On Sat, 3 Jan 2009 12:17:38 -0800 (PST), Chris <>
    wrote, quoted or indirectly quoted someone who said :

    >(By intereact I mean pass
    >arguments and text to it). Here's where I get stuck... Does anyone
    >know how I can accomplish this?


    see http://mindprod.com/jgloss/exec.html
    for more than you wanted to know about spawning bat files.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    PM Steven Harper is fixated on the costs of implementing Kyoto, estimated as high as 1% of GDP.
    However, he refuses to consider the costs of not implementing Kyoto which the
    famous economist Nicholas Stern estimated at 5 to 20% of GDP
    Roedy Green, Jan 5, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Achim Domma (Procoders)

    read input for cmd.Cmd from file

    Achim Domma (Procoders), Jun 3, 2005, in forum: Python
    Replies:
    2
    Views:
    8,027
    Peter Otten
    Jun 3, 2005
  2. Sarir Khamsi

    Interpreter-like help in cmd.Cmd

    Sarir Khamsi, Jun 9, 2005, in forum: Python
    Replies:
    4
    Views:
    347
    Bengt Richter
    Jun 26, 2005
  3. =?ISO-8859-1?Q?Sch=FCle_Daniel?=

    [exec cmd for cmd in cmds]

    =?ISO-8859-1?Q?Sch=FCle_Daniel?=, Mar 8, 2006, in forum: Python
    Replies:
    3
    Views:
    365
    Scott David Daniels
    Mar 8, 2006
  4. Diez B. Roggisch

    pydb remote debugging/cmd.Cmd over socket?

    Diez B. Roggisch, May 28, 2008, in forum: Python
    Replies:
    2
    Views:
    535
    Diez B. Roggisch
    May 29, 2008
  5. Diez B. Roggisch

    cmd.Cmd bug or at least docu-bug

    Diez B. Roggisch, May 29, 2008, in forum: Python
    Replies:
    1
    Views:
    322
    Michele Simionato
    May 29, 2008
Loading...

Share This Page