?
Solved

how to start a new console where to send output

Posted on 2003-02-19
12
Medium Priority
?
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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 …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

765 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