Insert text to console application? (win)

Archives Forums/Win32 Discussion/Insert text to console application? (win)

zzz(Posted 2012) [#1]
Im having troubles finding a solution for this.. I dont have much experience with scripting and this stuff, especially not on windows.

Say i have some application running in a console window that accepts user commands. How would i go about having another program/script send commands to it?

Looking to automate something, and preferably the solution would not get in the way of me issuing other commands now and then.

Thanks in advance


_PJ_(Posted 2012) [#2]
Not sure on the 'preferred' or "proper" means to do this, but a workaround might be to have the console app read from a text file or similar to get its commands on a (semi) regular basis, and have the other program responsible for writing/re-writing that text file?

That's how I would do it for "simplicity", not ideal for corporate /non-private use of course.


ziggy(Posted 2013) [#3]
The regular way to do this is by using Pipes, using the standard i/o stream, the standard error stream, and the standard input stream.
If you're on BlitzMax, the Process class has methods to read/write to the input/output streams of launched apps. (That's how the blitzMax debuger works, you can take a look to MaxIde source). That's the same on unix-based systems. So you launch a process from a front-end application, and this application can comunicate with the hosted one by writing and reading from its output / input streams. The output stream contains the information that the application would have been sending to the console window, and the input stream is the place to "send" the user input to the application.
Lots of graphical front-ends for command-line applications are done this way.