Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how to start a new console where to send output

Posted on 2003-02-19
12
Medium Priority
?
169 Views
Last Modified: 2012-05-04
This is the problem:
I made an application with some threads. Only one of those threads reads input from console. What I want to do is to have a console where the user can input datas and another console where the other threads print some informations. Can you help me?

Thank you.
0
Comment
Question by:Solarin
  • 7
  • 4
12 Comments
 

Author Comment

by:Solarin
ID: 7981069
i think it's worth more than 50. but i'm new :) and I dont have enough points
0
 

Author Comment

by:Solarin
ID: 7981070
--
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7981146
isn't it better to use GUI?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Solarin
ID: 7981214
no, i cant use GUI. it's a program for university and i was asked to do it in console mode.
0
 

Author Comment

by:Solarin
ID: 7981227
no, i cant use GUI. it's a program for university and i was asked to do it in console mode.
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7981371
You can create a class like this:

class Echo {
  public static void main(String[]) {
    int r;
    while ((r=System.in.read()) != -1) {
      System.out.write(r);
    }
  }
}

start this in a new console using:
Process p = Runtime.getRuntime().exec("java -cp ... Echo");
and take the input using:
InputStream in = p.getInputStream();

in will represent the input of the console of the Echo process
0
 

Author Comment

by:Solarin
ID: 7981656
ok, i create the first class Echo.
what about the second piece of code? i don't understand how to use it.
0
 
LVL 9

Expert Comment

by:Ovi
ID: 7981684
you should create different consoles for in and out by using Runtime.getRuntime.exec("command"); where 'command' for Windows is 'cmd' or "command", for linux 'bash' or 'sh'. The above invocation will reurn to you a handler to a Proccess object on which you will be able to query the outputStream, inputStream and errorStream - read/write on them.

You should know that the calls to exec() should be made on a separate thread to avoid application lock.
0
 
LVL 9

Accepted Solution

by:
Venci75 earned 200 total points
ID: 7981696
this code:
Process p = Runtime.getRuntime().exec("java -cp ... Echo");

will start a new Echo console application. To get the input of the Echo console, you must simply use:
InputStream in = p.getInputStream();
in.read(); // read from the console

to print to the echo console, use
OutputStream out = p.getOutputStream();
out.write(); // write the console

which is not clear?
0
 

Author Comment

by:Solarin
ID: 7981792
ok, the problem is that after

Process p = Runtime.getRuntime().exec("java -cp ... Echo");

a new console is created (i checked on the Task Manager) but it's not visible...
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7982013
hmmm...
try then
Process p = Runtime.getRuntime().exec("cmd /C java -cp ... Echo");
0
 

Author Comment

by:Solarin
ID: 7982069
ok tnks.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month11 days, 6 hours left to enroll

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question