Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Pipe is readable only when WinSCP has finished

Thanks for your post. This issue has been added to tracker.
Mercury

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.
Mercury

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.)
martin

Re: Pipe is readable only when WinSCP has finished

What do you do in your script?
Mercury

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:

    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...

    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?