PDA

Click to See Complete Forum and Search --> : pipelines ... program1.exe | program2.exe SOLVED


BramVandenbon
Mar 28th, 2004, 07:59 AM
- INTRODUCTION -
I'm working on a GoBot project.

Go is a worldfamous (asian) boardgame.
A lot of computerprograms are written for letting people play with GoBots.

And there are also a lot of Go Servers where people can play eachother.

Letting bots play on these servers has been impossible for a long time. But recently there is a new protocol "GTP".

each goserver makes his own bridge between the bot and its server.

- WHAT I DID -
I need 2 programs to communicate using standard input and standard output.

MS-DOS and linux users will propably know how this is done:

if you launche program1 like this ...
program1.exe | program2.exe

Then program 1 sends its output to the input of program2 and the other way round.

Program 1 is written in Java by the owners of the server. My program is written in C#but that doesn't really matter.

in my program I use Console.WriteLine() to send my commands. And indeed the other program receives all my commands.

- THE PROBLEM -

If I want to receive Input from the other program ...

I can't make a Console.readline() loop cause i never know in advance when the other program is going to send something. Using readline would make my program hang till i receive something and then make it hang again.

And even when i put my loop right behind my Writeline I don't receive the input because mostly my Readline is too late.

So I need some kind of event that gets triggered when i receive input. But the Console class doesn't contain this kind of thing.

I tried the In property of the Console class to put the input into a StreamReader object. But the same problem occures. When I'm using sr.Readline() the whole program hangs. and still the timing is impossible

- ... -
Does anybody have any experience with this kind of problems ?
I went through MSDN and didn't find any kind of information about it.

Thank you in advance

Tewl
Mar 28th, 2004, 08:07 AM
if you use threads your program will not hang

BramVandenbon
Mar 28th, 2004, 09:53 AM
indeed,
thank you. I made it in a thread ...

I did this like this

myThread = new System.Threading.Thread(new System.Threading.ThreadStart(inputloop));

I start the thread in my main like this:
myThread.Start();


and then I added this global var and procedure.

static ArrayList inputList = new ArrayList();

static private void inputloop()
{
string input;
do{
invoer = Console.ReadLine();
inputList.Add(input);
//MessageBox.Show("added:" + input);
}while (true);
}


No errors or stuff like this. But the strange thing is ... I still don't receive the commands. The strange thing is however: I can see the commands he's sending in my MS-DOS window. So it's like they are not send to the program at all.

When I type in some text in the DOS window and then hit return I do receive that in my program.

Anybody a suggestion or idea ?

Tewl
Mar 28th, 2004, 12:49 PM
is this a typo?


invoer = Console.ReadLine();


Should invoer be input?

BramVandenbon
Mar 28th, 2004, 02:16 PM
yes sorry, that's a part i forgot to translate, but in my actual program it's ok ;-)

still looking for a solution though ?

BramVandenbon
Apr 6th, 2004, 02:40 PM
seems like | only sends data in 1 direction. So I solved it by working like this



(progr1.exe | progr2.exe) > output.txt

and then progr1.exe copies output.txt to output2.txt at runtime (because it is locked). And then reads from it at runtime.

Doing all this using multithreading to avoid the blocking.
Thanks for all help, problem solved !