Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QProcess redirecting output streams produces empty files!

QProcess redirecting output streams produces empty files!

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 4.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    basilikus
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • J Offline
      J Offline
      joeuser
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cincirin
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved