QProcess redirecting output streams produces empty files!



  • Hi there!

    I'm trying to use QProcess to make a seperate process to use WinSCP. I have got the WinSCP side working using the windows process features, however I want to learn how to use QProcess.

    The problem is, using QProcess does not output the process information in the cmd window (unlike the windows version) and I need to know what is said - so my plan is to redirect the output to a file so that it can be then read back in and output.

    Anyway, below is the code which I use to make the process, however the files it produces are completely empty! (To clarify, the startString I know works, as I use it with the windows version so syntax and so forth is correct).

    @void UploadProcess::makeQtProcess(MyGui* gui, QString dirAddr, QString device)
    {
    m_pGui = gui;

    m_pProcess = new QProcess();

    m_pProcess->setStandardOutputFile ("C:\outputfile.txt");
    m_pProcess->setStandardErrorFile ("C:\errorfile.txt");

    m_pProcess->setProcessChannelMode(QProcess::SeparateChannels);

    QString startString = ""C:\Program Files\WinSCP\WinSCP.exe" /console /script="";
    startString += dirAddr;
    startString += "/Script.txt" /log="";
    startString += dirAddr;
    startString += "/";
    startString += device;
    startString += "/errorlog.log"";

    m_pProcess->start(startString, QIODevice::ReadWrite);
    m_pProcess->waitForFinished(-1);

        //Here I will put code to read back the information from the file.
    

    if (m_pProcess->exitStatus() == QProcess::NormalExit)
    {
    gui->log("OK!");
    }
    else
    {
    gui->log("Failed!");
    QString test = m_pProcess->errorString();
    gui->log(test);
    }

    delete m_pProcess;
    }@

    Thanks for your help in advance!

    Phil



  • What happens when this executes, do you get "OK" or "Failed"? And have you tried QProcess::waitForStarted to ensure the process actually did start? In my limited experience with QProcess I've had better luck with the QProcess::start(const QString & program, const QStringList & arguments) method. You don't have to worry so much about the quotes around the program name and parameters. But I only work in Linux so I don't know if you really need those quotes.



  • I don't tested, but try with "readAllStandardOutput":http://doc.qt.nokia.com/latest/qprocess.html#readAllStandardOutput


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.