open a pipe?

Does anyone know how to open a read/write pipe between a xojo application and an external command that uses stdin/stdout/stderr?

Mac? Win? Linux?

In MBS Plugins we have NSTaskMBS and NSPipeMBS classes for Mac OS X.

windows… for now.

You will find this topic interesting, and towards the end @Wayne Golding posted his implementation of a socket-like Xojo class for Win32 named pipes. The StdIn, StdOut, and StdErr streams are similar to named pipes insofar as you can construct a Xojo binarystream from them (see Wayne’s topic.) However, redirecting these IO streams (as far as I know) can only be done if the external command is launched with the proper call to CreateProcess (for an example of using CreateProcess to launch a child application but not redirect the standard IO handles, see the Windows Functionality Suite method LaunchAndWait.)

Create three unnamed pipes and use the read and write handles (Integer values, the first two parameters to the CreatePipe WinAPI function) to construct three BinaryStreams: one from the StdIn write handle, one from StdOut read, and one one from Stderr read. These are the ends of the pipes that belong to the main application. Use the StdIn read, StdOut write, and StrErr write handles in the STARTUPINFO structure that is passed to CreateProcess.

e.g. Creating a binarystream that can write to the child process’ StdIn stream.

Declare Function CreatePipe Lib "Kernel32" (ByRef ReadPipe As Integer, _ ByRef WritePipe As Integer, SecAttributes As Ptr, SuggestedBufferSize As Integer) As Boolean Dim StdInRead, StdInWrite As Integer If CreatePipe(StdInRead, StdInWrite, Nil, 512) Then ' Pass StdInRead to the child process via CreateProcess, create a binarystream from StdInWrite Dim StdInWriter As New BinaryStream(StdInWrite, BinaryStream.HandleTypeWin32Handle) End If

Note that this is untested advice. I’ve created pipes and created processes, but never at the same time :slight_smile:

whoah! :slight_smile: Nice. Thanks. I’ll try it!