P
parag
Hi there,
I want to communicate two threads using pipe. Also I want to make
this process as cyclic process, currently it is non-cyclic
I am posting my code below
pls suggest something...........
//Pipe Writer class
import java.io.*;
public class Pipe_Writer extends Thread {
PipedWriter pWriter = new PipedWriter();
public Pipe_Writer() {}
public PipedWriter getPipedWriter() {
return pWriter;
}
public void run() {
Process p = null;
try {
p = Runtime.getRuntime().exec("cmd");
} catch (IOException e) {
e.printStackTrace();
}
BufferedReader reader = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedWriter writer = new BufferedWriter(new
OutputStreamWriter(p.getOutputStream()));
BufferedReader reader2 = new BufferedReader(new
InputStreamReader(System.in));
String line;
String rd = "";
try {
rd = reader2.readLine();
System.out.println(rd);
} catch (IOException e1) {
e1.printStackTrace();
}
try {
// writer.write("dir\n"); //writing to process
writer.write(rd + "\n");
writer.flush();
while ((line = reader.readLine()) != null) {
System.out.println(line);
pWriter.write(line); //writing to pipe
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
=========================================
// Pipe reader class
import java.io.*;
public class Pipe_Reader extends Thread{
PipedReader pReader;
public Pipe_Reader(Pipe_Writer writer)throws IOException{
pReader = new PipedReader(writer.getPipedWriter());
}
public void run(){
try {
while(true){
System.out.println((char)pReader.read()); //Reading from pipe
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
=============================
// main method
public static void main(String[] args)throws IOException {
Pipe_Writer writer = new Pipe_Writer();
Pipe_Reader reader = new Pipe_Reader(writer);
writer.start();
reader.start();
}
====================================
pls HELP me!.....
I want to communicate two threads using pipe. Also I want to make
this process as cyclic process, currently it is non-cyclic
I am posting my code below
pls suggest something...........
//Pipe Writer class
import java.io.*;
public class Pipe_Writer extends Thread {
PipedWriter pWriter = new PipedWriter();
public Pipe_Writer() {}
public PipedWriter getPipedWriter() {
return pWriter;
}
public void run() {
Process p = null;
try {
p = Runtime.getRuntime().exec("cmd");
} catch (IOException e) {
e.printStackTrace();
}
BufferedReader reader = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedWriter writer = new BufferedWriter(new
OutputStreamWriter(p.getOutputStream()));
BufferedReader reader2 = new BufferedReader(new
InputStreamReader(System.in));
String line;
String rd = "";
try {
rd = reader2.readLine();
System.out.println(rd);
} catch (IOException e1) {
e1.printStackTrace();
}
try {
// writer.write("dir\n"); //writing to process
writer.write(rd + "\n");
writer.flush();
while ((line = reader.readLine()) != null) {
System.out.println(line);
pWriter.write(line); //writing to pipe
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
=========================================
// Pipe reader class
import java.io.*;
public class Pipe_Reader extends Thread{
PipedReader pReader;
public Pipe_Reader(Pipe_Writer writer)throws IOException{
pReader = new PipedReader(writer.getPipedWriter());
}
public void run(){
try {
while(true){
System.out.println((char)pReader.read()); //Reading from pipe
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
=============================
// main method
public static void main(String[] args)throws IOException {
Pipe_Writer writer = new Pipe_Writer();
Pipe_Reader reader = new Pipe_Reader(writer);
writer.start();
reader.start();
}
====================================
pls HELP me!.....