Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
924 views
in Technique[技术] by (71.8m points)

how to bind a windows console application with java application?

i have an executable program (.exe) writen in c++ and run on windows console and i have a java swing applecation , so i want my java application to interact with the console app (send input and get output) . but how to do that ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can do it this way

// Create the proccess in JAVA
Process proc = Runtime.getRuntime().exec("Name of application");

// Receive outputs from another program inside Java by a stream
InputStream ips = proc.getInputStream();

// Using the stream to get the messages from another program
String output = "";
int c = 0;
while ((c = ips.read()) != -1){
    output+= (char)c;
}

//Inputs messages into another program
OutputStream ops = proc.getOutputStream();
ops.write("an byte array");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...