Re: Pipe is readable only when WinSCP has finished
Thanks for your post. This issue has been added to tracker.
Before posting, please read how to report bug or request support effectively.
Bug reports without an attached log file are usually useless.
SECURITY_ATTRIBUTES sa;
// Security attributes
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = true;
SECURITY_DESCRIPTOR sd;
if (IsWinNT())
{
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, true, NULL, false);
sa.lpSecurityDescriptor = &sd;
}
// Stdout/stderr pipe
// read = outside, write = inside
CreatePipe(&hStdOutOutside, &hStdOutInside, &sa, 1024*10);
// Stdin pipe
// read = inside, write = outside
CreatePipe(&hStdInInside, &hStdInOutside, &sa, 1024*10);
// Startup info
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
si.dwFlags |= STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
si.hStdOutput = hStdOutInside;
si.hStdError = hStdOutInside;
si.hStdInput = hStdInInside;
si.wShowWindow = SW_HIDE;
// cmdline
xchar* cmdl = new xchar[1024]; //xstrlen(aFname)+xstrlen(aCmdLine) + 10];
xsprintf(cmdl, "\"%s\" %s", aFname, aCmdLine);
// process info
PROCESS_INFORMATION pi;
CreateProcessA(
NULL, // lpApplicationName
cmdl, // lpCommandLine
NULL, // lpProcessAttributes
NULL, // lpThreadAttributes
true, // bInheritHandles
0, // dwCreationFlags
NULL, // lpEnvironment
NULL, // lpCurrentDirectory
&si, // lpStartupInfo
&pi ); // lpProcessInformation
unsigned long nbr, nbr2, nba, nbl;
PeekNamedPipe(
hStdOutOutside, aBuf, aLength,
&nbr, &nba, &nbl);
if (nbr>0)
{
ReadFile(
hStdOutOutside, aBuf, nbr, &nbr2, NULL);
return nbr2;
} else return 0;