Results 1 to 4 of 4
- 11-10-2008, 04:42 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 5
- Rep Power
- 0
can you give-me a little hand about java threads?
I have done this so far, but I am getting an error on main class
I believe its how to get the command (BufferedReader and StringTokenizer methods)
Please give me a hint. Code Below:
by the way, I have to create myshell with differents commands working in differents threads.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class MyShell
{
public static void main(String args[]) throws IOException
{
boolean exit = false;
while (!exit)
{
// Modification of txt into String
System.out.println("There is MyShell >>> ");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
// Devide whole string into different sub-strings(tokens)
// and check if there is more tokens to read.
String input = in.readLine();
StringTokenizer token = new StringTokenizer(input, "&");
while(token.hasMoreTokens())
{
String[] command = new String[3];
command[0] = "cdm.exe";
command[1] = "/C";
command[2] = token.nextToken();
if(command[2].equals("exit"))
{
System.exit(0);
exit = true;
}
Runtime run = Runtime.getRuntime();
Process proc = run.exec(command);
thread_1 errorMessage = new thread_1(proc.getErrorStream(), "ERRORp");
thread_1 outputMessage = new thread_1(proc.getInputStream(), "Output ");
errorMessage.start();
outputMessage.start();
}
}
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
class thread_1 extends Thread
{
InputStream input;
String str;
thread_1(InputStream input, String str)
{
this.str = str;
this.input = input;
}
// Override run method
public void run()
{
try
{
InputStreamReader iReader = new InputStreamReader(input);
BufferedReader bReader = new BufferedReader(iReader);
String output = null;
while ((output = bReader.readLine())!= null)
System.out.println(str + ">>> " + output);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
- 11-10-2008, 05:14 PM #2
See post in your other thread.
One thread is enough!!!
- 11-10-2008, 05:35 PM #3
Member
- Join Date
- Nov 2008
- Posts
- 5
- Rep Power
- 0
sorry about that
- 11-10-2008, 06:15 PM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
Please don't post the same thread in different sub-forums. Choose the correct one and ask your question more clearly.
Similar Threads
-
how can i give a file path to java stream ?
By sheckoo in forum New To JavaReplies: 2Last Post: 11-05-2008, 09:42 AM -
Can someone give me a helping hand...
By kwesiaryee in forum Advanced JavaReplies: 1Last Post: 09-17-2008, 08:11 PM -
Really Would use a hand
By mollentze in forum New To JavaReplies: 7Last Post: 07-03-2008, 03:30 PM -
Reading a file into java and give it out
By little_polarbear in forum New To JavaReplies: 7Last Post: 06-05-2008, 11:32 AM -
I must create a robotic hand with java .... any one can help ??
By yashar in forum New To JavaReplies: 9Last Post: 03-25-2008, 04:46 PM
Bookmarks