Pipe is readable only when WinSCP has finished
I use WinSCP as a part of a larger program. It calls WinSCP.com in such a manner:
To read the output, I use such an instruction...
The output appears on my end of pipe only after WinSCP has finished => the program cannot interact with WinSCP (it can only feed predefined scripts). Other programs (for example, cmd.exe) seem to be OK.
What to do? Maybe, wrong code?
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 ); // lpProcessInformationTo read the output, I use such an instruction...
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;The output appears on my end of pipe only after WinSCP has finished => the program cannot interact with WinSCP (it can only feed predefined scripts). Other programs (for example, cmd.exe) seem to be OK.
What to do? Maybe, wrong code?