Results 1 to 6 of 6

Thread: pipelines ... program1.exe | program2.exe SOLVED

  1. #1

    Thread Starter
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 2002
    Location
    Belgium
    Posts
    502

    pipelines ... program1.exe | program2.exe SOLVED

    - 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
    Last edited by BramVandenbon; Apr 6th, 2004 at 02:41 PM.

  2. #2
    Addicted Member
    Join Date
    Jun 2003
    Location
    Birmingham, AL
    Posts
    188
    if you use threads your program will not hang

  3. #3

    Thread Starter
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 2002
    Location
    Belgium
    Posts
    502
    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.
    Code:
    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 ?
    ____________________________________________

    Please rate my messages. Thank you!
    ____________________________________________
    Bram Vandenbon
    http://www.bramvandenbon.com

  4. #4
    Addicted Member
    Join Date
    Jun 2003
    Location
    Birmingham, AL
    Posts
    188
    is this a typo?

    Code:
      invoer = Console.ReadLine();
    Should invoer be input?

  5. #5

    Thread Starter
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 2002
    Location
    Belgium
    Posts
    502
    yes sorry, that's a part i forgot to translate, but in my actual program it's ok ;-)

    still looking for a solution though ?
    Last edited by BramVandenbon; Mar 29th, 2004 at 11:36 AM.
    ____________________________________________

    Please rate my messages. Thank you!
    ____________________________________________
    Bram Vandenbon
    http://www.bramvandenbon.com

  6. #6

    Thread Starter
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 2002
    Location
    Belgium
    Posts
    502
    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 !
    ____________________________________________

    Please rate my messages. Thank you!
    ____________________________________________
    Bram Vandenbon
    http://www.bramvandenbon.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width