Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

easy (easiest) interprocess communication via stdin/stdout pipes

Status
Not open for further replies.

Olaf Doschke

Programmer
Oct 13, 2004
14,847
DE
It's very easy to start an exe and communicate with it via stdin/stdout, by using Wscript.Shell:

Code:
oWSH = CreateObject("Wscript.Shell")
oExec = oWSH.Exec("C:\somedir\someapp.exe")
oExec.StdIn.WriteLine("Send in Value/Command")
oExec.StdOut.ReadLine() && or Read() or ReadAll()

A simple example with cmd.exe and dir output:
Code:
oWSH = CreateObject("Wscript.Shell")
CD (Home())
oExec = oWSH.Exec("cmd.exe /c dir")
? oExec.StdOut.ReadAll()

StdIn and StdOut are the standard pipes you might remember from DOS times you could pipe stdout to the next process with | or redirect it with >, eg to a file or device.

The called exe will of unfortunately also show up, unless it's windowless. If you have that under your control, eg you are the developer of the exe, that's up to you. In this case you can use this as communication without files. What's missing is an event occurring when the called exe returns something via it's stdout or stderr pipe (or both), but it's good for situations not taking long. You can also keep the executed process running (like a service, but without the headache of creating a real service or setting up SrvAny) and send in commands when needed and receive the answers. It's up to you to define a communication protocol as you like.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top