Cmd Prompt qustion

C

Chris

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

Arne Vajhøj

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

Roedy Green

(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
 

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,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top