Process Builder Question

Discussion in 'Java' started by Chris, Jun 28, 2008.

  1. Chris

    Chris Guest

    All- I type the following into my command prompt and it works fine:

    DogTrainingCommand.exe /text="Testing 123, Testing 123." /voice="dog"

    (that is once I have done: cd C:/Program Files/PetTraining/T120)

    However, when I try to automate this using ProcessBuilder in a java
    app nothing happens? My program terminates as soon as I run it and I
    get no output. Can you correct me in what I am doing wrong?
    Thank you in advance for your time!


    import java.io.IOException;
    import java.io.*;

    public class CmdPrompt {
    public static void main(String args[])
    {
    try {
    ProcessBuilder pb = new
    ProcessBuilder("DogTrainingCommand.exe", "\\text = Testing 123,
    Testing123", "\\voice = dog");
    pb.directory(new File("C:\\Program Files\\PetTraining\
    \T120"));
    Process p = pb.start();
    }
    catch (IOException e)
    {
    }
    }

    }
    Chris, Jun 28, 2008
    #1
    1. Advertising

  2. Chris

    Arne Vajhøj Guest

    Chris wrote:
    > All- I type the following into my command prompt and it works fine:
    >
    > DogTrainingCommand.exe /text="Testing 123, Testing 123." /voice="dog"
    >
    > (that is once I have done: cd C:/Program Files/PetTraining/T120)
    >
    > However, when I try to automate this using ProcessBuilder in a java
    > app nothing happens? My program terminates as soon as I run it and I
    > get no output. Can you correct me in what I am doing wrong?
    > Thank you in advance for your time!
    >
    >
    > import java.io.IOException;
    > import java.io.*;
    >
    > public class CmdPrompt {
    > public static void main(String args[])
    > {
    > try {
    > ProcessBuilder pb = new
    > ProcessBuilder("DogTrainingCommand.exe", "\\text = Testing 123,
    > Testing123", "\\voice = dog");
    > pb.directory(new File("C:\\Program Files\\PetTraining\
    > \T120"));
    > Process p = pb.start();
    > }
    > catch (IOException e)
    > {
    > }
    > }
    >
    > }


    Why are you "escaping" a / to \\ ??

    Arne
    Arne Vajhøj, Jun 28, 2008
    #2
    1. Advertising

  3. Chris

    Daniel Pitts Guest

    Chris wrote:
    > All- I type the following into my command prompt and it works fine:
    >
    > DogTrainingCommand.exe /text="Testing 123, Testing 123." /voice="dog"
    >
    > (that is once I have done: cd C:/Program Files/PetTraining/T120)
    >
    > However, when I try to automate this using ProcessBuilder in a java
    > app nothing happens? My program terminates as soon as I run it and I
    > get no output. Can you correct me in what I am doing wrong?
    > Thank you in advance for your time!
    >
    >
    > import java.io.IOException;
    > import java.io.*;
    >
    > public class CmdPrompt {
    > public static void main(String args[])
    > {
    > try {
    > ProcessBuilder pb = new
    > ProcessBuilder("DogTrainingCommand.exe", "\\text = Testing 123,
    > Testing123", "\\voice = dog");
    > pb.directory(new File("C:\\Program Files\\PetTraining\
    > \T120"));
    > Process p = pb.start();
    > }
    > catch (IOException e)
    > {
    > }
    > }
    >
    > }

    you need to start a thread or two, to read from p.getInputStream() and
    p.getErrorStream(), and do the "right thing" with that data.

    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
    Daniel Pitts, Jun 28, 2008
    #3
  4. Chris

    Chris Guest

    On Jun 27, 5:43 pm, Daniel Pitts
    <> wrote:
    > Chris wrote:
    > > All- I type the following into my command prompt and it works fine:

    >
    > > DogTrainingCommand.exe /text="Testing 123, Testing 123." /voice="dog"

    >
    > > (that is once I have done: cd C:/Program Files/PetTraining/T120)

    >
    > > However, when I try to automate this using ProcessBuilder in a java
    > > app nothing happens? My program terminates as soon as I run it and I
    > > get no output. Can you correct me in what I am doing wrong?
    > > Thank you in advance for your time!

    >
    > > import java.io.IOException;
    > > import java.io.*;

    >
    > > public class CmdPrompt {
    > >  public static void main(String args[])
    > >  {
    > >    try {
    > >         ProcessBuilder pb = new
    > > ProcessBuilder("DogTrainingCommand.exe", "\\text = Testing 123,
    > > Testing123", "\\voice = dog");
    > >         pb.directory(new File("C:\\Program Files\\PetTraining\
    > > \T120"));
    > >         Process p = pb.start();
    > >         }
    > >    catch (IOException e)
    > >         {
    > >         }
    > >    }

    >
    > > }

    >
    > you need to start a thread or two, to read from p.getInputStream() and
    > p.getErrorStream(), and do the "right thing" with that data.
    >
    > --
    > Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>- Hide quoted text -
    >
    > - Show quoted text -


    Thank you for your advice, after reediting, I guess my question more
    specifically is with the arguments that I need to pass. That is, I use
    forward slashes, quotes, and parenthesis in the command line and it
    seems like that is what is tripping this up. Are there characters that
    I need to encompass quotes, slashes, and parentheses with for the
    arguments to pass?
    Thank you.


    import java.io.*;

    public class CmdPrompt {
    public static void main(String args[]) throws IOException {
    ProcessBuilder p = new ProcessBuilder("DogTrainingCommand.exe","/
    text Testing 123", "/voice (dog)");
    p.directory(new File("C:\\Program Files\\PetTraining\\T120"));
    Process pcs = p.start();
    InputStream is = pcs.getInputStream();
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    String line;
    while ((line = br.readLine()) != null) {
    System.out.println(line);
    }
    }
    }
    Chris, Jun 28, 2008
    #4
    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. Meidan

    Process Builder

    Meidan, Dec 27, 2005, in forum: Java
    Replies:
    2
    Views:
    1,035
    Roedy Green
    Dec 27, 2005
  2. Bassa
    Replies:
    0
    Views:
    968
    Bassa
    Sep 19, 2003
  3. Jakub Dudek
    Replies:
    1
    Views:
    423
    Peter van Merkerk
    Aug 29, 2003
  4. Miguel PS
    Replies:
    1
    Views:
    486
    Miguel PS
    Apr 2, 2004
  5. Phlip
    Replies:
    5
    Views:
    545
    Stefan Behnel
    Jan 13, 2010
Loading...

Share This Page