mgazza
asked on
cmd execute
hi i want to write data the stdin of a cmd program
i currently use
createpipe( hread, hwrite...
createprocess etc
when should i write the data to hwrite ?
regards mark,
i currently use
createpipe( hread, hwrite...
createprocess etc
when should i write the data to hwrite ?
regards mark,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i need to write to stdin
just cant write to the programs input buffer duno if its possable
its just that i cant send post data to php.exe
the propper way to ex cmd
function CMDExecute(Fcommand:string
Const
BufSize= 4194304;
var
SecAttr: TSecurityAttributes;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInform
WriteHandle, ReadHandle: THandle;
ReadBuf: Array[0..1023]of char;
BytesRead, BytesTotal: DWORD;
GetExitCodeResult: DWORD;
begin
SecAttr.nLength := SizeOf( SecAttr );
SecAttr.lpSecurityDescript
SecAttr.bInheritHandle := True;
if not CreatePipe(ReadHandle, WriteHandle, @SecAttr, BufSize) then
begin
Result :=GetLastError;
Exit;
end;
FillChar(StartupInfo,SizeO
with StartupInfo do
begin
cb:= SizeOf(StartupInfo);
dwFlags:= STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
hStdOutput:= WriteHandle;
hStdError:= WriteHandle;
wShowWindow:= SW_Hide;
end;
FillChar(ReadBuf, SizeOf(ReadBuf), 0);
if not CreateProcess(nil, PChar(FCommand), nil, nil,
True, DETACHED_PROCESS or NORMAL_PRIORITY_CLASS {or
CREATE_SEPARATE_WOW_VDM},
nil, nil, StartupInfo, ProcessInfo) then
Result:= GetLastError
else
begin
WaitForSingleObject(Proces
GetExitCodeProcess(Process
Result := GetExitCodeResult;
if Result = STILL_ACTIVE then TerminateProcess(ProcessIn
CloseHandle(ProcessInfo.hP
CloseHandle(ProcessInfo.hT
PeekNamedPipe(ReadHandle, @ReadBuf, sizeof(ReadBuf), @BytesRead, @BytesTotal,nil);
while BytesRead <> 0 do begin
BytesRead := 0;
ReadFile(ReadHandle, ReadBuf, sizeof(ReadBuf), BytesRead, nil);
stdout.Write(ReadBuf[0], BytesRead);
PeekNamedPipe(ReadHandle, @ReadBuf, sizeof(ReadBuf), @BytesRead, @BytesTotal,nil);
end;
end;
CloseHandle(WriteHandle);
end;
regards mark