Process Builder Question

C

Chris

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)
{
}
}

}
 
A

Arne Vajhøj

Chris said:
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
 
D

Daniel Pitts

Chris said:
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.
 
C

Chris

Chris said:
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.

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top