Results 1 to 6 of 6

Thread: Sending command to opened console window

  1. #1

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    58

    Sending command to opened console window

    Hi guys,

    I am working with a chess engine and trying to establish communication between my VB6 program and the engine.

    The engine does not accept parameters as input, I need to send a series of commands to the engine, capture the output (I found a way to do that already, but new suggestions are most welcome! the engine doesn't produce text file though), run another command and so on.

    The matter is that with another engine I was working, I could simply call the name of the engine using Shell command, along with parameters that I needed, and write them into the file.

    I already tried Batch files, it doesn't work because apparently when I run the engine, it takes a few moments before it gets ready for the next command, so it ignores the second command from the batch file.

    One possible way I was thinking of was to call the engine from VB6 shell, then send another command to the particular console again, how is it possible? I would explain more in details so you can get what I am looking for:

    1. Call Engine.exe
    'The engine console is opened now, after 2 seconds it's ready to accept another command
    2. Send another command to the engine to get ready (the console that has been opened already)
    'This command also takes a few seconds (depending on a few factors) to respond.
    3. Send a chess position and get the results back (another command to the opened console)
    'This command could take up to 30 seconds depending on lots of factors.


    My main concern is not about the delays, I can handle them with a flag check or something, now the point is how do I identify the opened console, and send another command to it.


    Thanks for any opinion!
    Ali.

  2. #2
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Sending command to opened console window

    Ali

    Have you considered using a Timer control?
    You could set it to "fire" once a second.
    • You could have it initially wait the 2 seconds .
    • Then you could have it wait until it "detected" that a reply had
      been received (be it 30 seconds, or whatever) and have it then
      send the next command. This would be repeated as needed.


    Spoo

  3. #3

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    58

    Re: Sending command to opened console window

    Thanks Spoo,

    I tried your suggestion, wrote those two commands in a batch file with giving a delay between the first command and the second one. It doesn't work, I think the problem is that after I run the first command, engine.exe, the environment changes and it's not command prompt anymore (though it's still in the console), but the second command never shows up.

    How do you think I can force the second command to "get place" regardless of the current environment but in the same window/console?

  4. #4
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Sending command to opened console window

    Ali

    I'm shooting in the dark here (having not tried something like
    this before), but I'm a little confused by your reply, specifically
    the reference to a batch file.

    I was thinking that in your Timer sub, you would use the
    Shell function. Is that what you did?

    Spoo

  5. #5

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    58

    Re: Sending command to opened console window

    Spoo,

    Okay, let me explain a bit more.

    First thing I was trying to do was to run the series of commands I need from the Shell Function. The problem is that once I send the first command "engine.exe" to the console, the environment changes from command-prompt to Houdini.exe (name of the engine), so the following commands would run another instance of the command-prompt and wont get place in the Houdini window anymore.

    Then, I tried to send the series of commands using a batch-file (forget about VB6, if I can get it done from a batch file so I can just call the batch file from a Shell command in VB).

    Now, I tried to send the first command in the batch file, make a delay of 5 seconds, then issue the second command; the same happens, the command-prompt environment changes and the second command doesn't do anything neither shows up.

    That's how I switched from Shell Function to Batch-File, sorry for the ambiguous explanation by the way.

  6. #6

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    58

    Re: Sending command to opened console window

    Spoo and others,

    I have been doing some coding to run a console from VB and then get control over it. I will be glad to hear your opinion about it, I created another thread at here.

    Thanks.

Tags for this Thread

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