Skip to main content
GameDev.net gamedev.net
🔒 Locked

providing input to another process

Started by docyoung83 Nov 1, 2005 at 5:11 PM 2 replies 400+ views
Original Post
docyoung83
docyoung83
There is a console program that I am interested in writing a GUI application for, but the problem is that the console program does not take parameters on the command line. The parameters are prompted for as the program is run. Therefore, I am a bit confused as to how to get my GUI application to send the right parameters and the right time, as well as how I'd even go about doing this in the first place. The basic setup of the console program is as follows: C:\>converter.exe Welcome to Converter! INPUT FORMAT> bmp OUTPUT FORMAT> jpg FILENAME> image1.bmp Done! The parameters "bmp", "jpg", and "image1.bmp" are all parameters that the user enters after the program is started. Thanks in advance. I imagine the answer has to do with pipes, but I am having trouble understanding them. If the only solution is more reading, I guess I'll just have to get down to it.
stylin
stylin
Create a text file like this:
input_formatoutput_formatfilename.extension

Now execute the command:

converter.exe < text.file

which will use that file for standard input.
:stylin: "Make games, not war." "...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid
docyoung83
docyoung83
Wow, quite a bit easier than I had anticipated. Thanks for the help!
Zipster
Zipster
In Windows, you have one of two choices, to use anonymous pipes or a named pipes. Anonymous pipes only allow one-way communication but are extremely easy to use. Named pipe allow for full-duplex communication but are (I believe) quite difficult and burdensome to use for simple two-way interprocess communication. My suggestion is to use two anonymous pipes, one for each communication direction. MSDN's section on anonymous pipes should get you started on creating and using them. There's an especially useful example linked at the bottom of the page called Creating a Child Process with Redirected Input and Output which is exactly what you want.

This is the general solution when you want to create a GUI frontend for a console application. You could also create a file and just redirect input as stylin suggested, however that's more for console applications that just do quick data processing and don't really drive the GUI. It looks like that's what you wanted though, so good luck to you.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.