1

Im trying to create a GUI wrapper application for a dos utility. When I execute my dos utility application(dosapp.exe) in console look like this:

-------------------------
WELCOME
------------------------
What do you want to do?
1- Type 1 ,For Enter System
2- Type 2 ,Set Properties
3- TYpe 3, Exit
Enter Action:

On my delphi xe3 application, I have three buttons one for each action and I run dosapp.exe using CreateProcess and Pipes to capture response.

My Problem is how to write the actions on console process for my 3 buttons pulsations, for example, when the user click on button1 I need send to running created process(dosapp.exe) writeline("1") and get response. I saw some examples for C# when this can by easy do it using process class and invoking Process.StandardInput.WriteLine("1")But i can't doit on delphi, Any idea or hint.


edited: Finally Solved according David Heffman Comments.

David A
  • 763
  • 1
  • 9
  • 22
  • 2
    This might be of help: http://stackoverflow.com/questions/2015388/how-to-send-command-to-console-application-from-gui-application – Merlin W. Dec 15 '13 at 07:37
  • 3
    Create a pipe. Make sure it's read end is inheritable. Call CreateProcess to start the other process. Pass the read end of the pipe as the new process stdin. Write onto the write end of the pipe. Do the same in reverse if you need to capture stdout. – David Heffernan Dec 15 '13 at 09:27
  • 1
    Perhaps the first and most important question (but only because you say: "When I execute ***my*** dos utility application...") is to ask: If it's ***your*** application, do you also have the source code (even if it's in a different language)? The reason I ask is that it is much easier and more robust to wrap code (even via DLL) than it is to wrap a console user interface which might require screen scraping to interpret the responses you get. – Disillusioned Dec 15 '13 at 15:50
  • 1
    I seriously suspect it isn't a DOS application, but a native Win32 console application. – Andreas Rejbrand Dec 15 '13 at 17:41
  • @CraingYoung , DosApplication it's not created by me, so i don't have a sourcecode. – David A Dec 15 '13 at 20:30
  • @DavidHeffernan Thx, for response, Do it using pipes it's the right way. I thought that in new XE delphi versions any class like Process in c# exit, but it's not. – David A Dec 15 '13 at 20:32

1 Answers1

1

Accepted answer as mentioned in comments:

Create a pipe. Make sure it's read end is inheritable. Call CreateProcess to start the other process. Pass the read end of the pipe as the new process stdin. Write onto the write end of the pipe. Do the same in reverse if you need to capture stdout.

Kromster
  • 7,181
  • 7
  • 63
  • 111