[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

08/23/2003 at 12:44PM PDT, ID: 20718158
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.8

InputStreams / OutputStreams on Process class in Java

Asked by uniar in Java Programming Language

Tags: class, inputstreams, java

Hello.  I was hoping you could help me out with a small problem I'm having.  More points will be added to this question as I get them lol.

In any case, here's the problem:
I'm writing a java program that will act as a shell in windows xp / 2000 (can be adapted for 98 by launching a new instance of command instead of cmd I think. . . not sure though, haven't tried it).  In any case, something's wrong with it as it either A) won't accept input or B) won't read the output right, I'm not quite sure how to decide.  All this is new to me, I'm used to doing GUI work instead of trying to mess with buffers and the like.

import java.io.*;

public class remote{
     static int start=0;
 public static void main(String[] args) {
   try {
     Process p = Runtime.getRuntime().exec("cmd.exe");
     BufferedInputStream is = (BufferedInputStream)p.getInputStream(); //Typecasting to buffered i/o streams
     BufferedOutputStream os = (BufferedOutputStream)p.getOutputStream();
     
     t thre = new t(os); //need to start an input thread so that input may be passed to the program
     Thread thr = new Thread(thre);
     thr.start();
     int[] read = new int[50000];
     int i=0;
     while(true){
     read[i] = is.read(); //read the stream forever
     if(read[i]==10){ //test for ascii characters 10 and 13, both preceding a new line, so I assume that they're \r and \n, respectively
     System.out.print("\r");
     }
     else if(read[i]==13){
     System.out.print("\n");      
     }
     else{
     System.out.print((char)read[i]); //if no special characters, print out the character
     }

     i++;
        }
   } catch(Exception e) {
     e.printStackTrace();
   }
 }
}

class t extends Thread{

/*
This thread is designed to accept input and pass it to the program.
*/

BufferedOutputStream os;

public t(BufferedOutputStream bos){
this.os = bos;
}

public void run(){
BufferedReader bufRead = new BufferedReader(new InputStreamReader(System.in)); //catching input from the system
String s;
while(true){

try{
s=bufRead.readLine(); //accepting input
os.write(s.getBytes()); //writing it to the buffer in a byte[] format
os.flush();                     //passing output from the buffer to the command shell
}
catch(IOException err){
      
}


}
}
}

Any assistance would be appreciated.  Thanks!
[+][-]08/25/03 12:01 AM, ID: 9214498

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/25/03 02:13 AM, ID: 9214890

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/25/03 02:17 AM, ID: 9214902

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Java Programming Language
Tags: class, inputstreams, java
Sign Up Now!
Solution Provided By: doronb
Participating Experts: 2
Solution Grade: A
 
 
[+][-]12/04/03 05:22 AM, ID: 9874202

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/11/03 02:11 PM, ID: 9923984

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91