Topic "Pipe is readable only when WinSCP has finished"

Author Message
Mercury

Guest


I use WinSCP as a part of a larger program. It calls WinSCP.com in such a manner:

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 );          // lpProcessInformation


To read the output, I use such an instruction...

Code:

    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?
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
What do you do in your script?
_________________
Martin Prikryl
Mercury

Guest


I don't use script. I try to pass these commands using stdin:

open someconnection
close
exit

(no real interaction by now, but there'll be.)
Mercury

Guest


The same happens to files. I write

WinSCP.com /script=somelongscript.sc >file.txt

F3 - the file is empty
F3 - it's empty again!!
F3 - empty!!!
After some tries, all the information appears in file.txt in one piece.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
Thanks for your post. This issue has been added to tracker.
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License