As Long dwX
, dwY
, dwXSize
, dwYSize
, dwXCountChars
, dwYCountChars
, dwFillAttribute
, dwFlags
As _Offset lpReserved2
, hStdInput
, hStdOutput
, hStdError
Const STARTF_USESTDHANDLES
= &H00000100 Const CREATE_NO_WINDOW
= &H8000000 Const HANDLE_FLAG_INHERIT
= &H00000001 Const STD_OUTPUT_HANDLE
= -11 Const GENERIC_READ
= &H80000000 Const FILE_ATTRIBUTE_READONLY
= 1 Const INVALID_HANDLE_VALUE
= -1
Dim Shared As _Offset hChildStd_IN_Rd
, hChildStd_IN_Wr
, hChildStd_OUT_Rd
, hChildStd_OUT_Wr
, hInputFile
Dim As SECURITY_ATTRIBUTES saAttr
Print "->Start of parent execution."
saAttr.nLength
= Len(saAttr
)saAttr.bInheritHandle = 1
saAttr.lpSecurityDescriptor = 0
ErrorExit "StdoutRd CreatePipe"
If SetHandleInformation
(hChildStd_OUT_Rd
, HANDLE_FLAG_INHERIT
, 0) = 0 Then ErrorExit "Stdout SetHandleInformation"
ErrorExit "Stdin CreatePipe"
If SetHandleInformation
(hChildStd_IN_Wr
, HANDLE_FLAG_INHERIT
, 0) = 0 Then ErrorExit "Stdin SetHandleInformation"
CreateChildProcess
WriteToPipe
Print "Contents of loremipsum.txt written to child STDIN pipe" Print "Contents of child process STDOUT:" ReadFromPipe
Print "->End of parent execution"
Sub CreateChildProcess
() Dim As PROCESS_INFORMATION piProcInfo
Dim As STARTUPINFO siStartInfo
siStartInfo.cb
= Len(siStartInfo
) siStartInfo.hStdError = hChildStd_OUT_Wr
siStartInfo.hStdOutput = hChildStd_OUT_Wr
siStartInfo.hStdInput = hChildStd_IN_Rd
siStartInfo.dwFlags = STARTF_USESTDHANDLES
bSuccess
= CreateProcess
(0, _Offset(szCmdline
), 0, 0, 1, CREATE_NO_WINDOW
, 0, 0, _Offset(siStartInfo
), _Offset(piProcInfo
)) ErrorExit "CreateProcess"
closeh = HandleClose(piProcInfo.hProcess)
closeh = HandleClose(piProcInfo.hThread)
closeh = HandleClose(hChildStd_OUT_Wr)
closeh = HandleClose(hChildStd_IN_Rd)
Dim As _Offset hInputFile: hInputFile
= CreateFile
("loremipsum.txt" + Chr$(0), GENERIC_READ
, 0, 0, OPEN_EXISTING
, FILE_ATTRIBUTE_READONLY
, 0) bSuccess
= ReadFile
(hInputFile
, _Offset(chBuf
), BUFSIZE
, _Offset(dwRead
), 0) bSuccess
= WriteFile
(hChildStd_IN_Wr
, _Offset(chBuf
), dwRead
, _Offset(dwWritten
), 0) If hInputFile
= INVALID_HANDLE_VALUE
Then ErrorExit "CreateFile"
If HandleClose
(hChildStd_IN_Wr
) = 0 Then ErrorExit "StdInWr CloseHandle"
Dim As _Byte closeh: closeh
= HandleClose
(hInputFile
)
Dim As _Offset hParentStdOut: hParentStdOut
= GetStdHandle
(STD_OUTPUT_HANDLE
) bSuccess
= ReadFile
(hChildStd_OUT_Rd
, _Offset(chBuf
), BUFSIZE
, _Offset(dwRead
), 0)
Print Reason
, GetLastError