Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

command chaining didn't work and no value



  • I try to run this command using QProcess

    curl "http://dbpedia.org/data/Haeinsa.json" | perl dbpediaPlaceData.txt 'Haeinsa'
    

    I made QObject class and used timer . I can't get value from perlProcess.
    Data is Json value.

    ProcessManager::ProcessManager(const QString& keyword,int max_processes, QObject *parent) :
          QObject(parent),
          _num_process(1)
          ,_max_processes(max_processes)
           ,curlProcess(new QProcess(this))
          ,perlProcess(new QProcess(this))
          ,dbpediaPlaceFile("")
          ,mKeyword(keyword)
    
    {
        createPath();
        perlProcess->setStandardOutputProcess(perlProcess);
    
        QUrl baseUrl = QUrl(QString("http://dbpedia.org/data/%1.json").arg(mKeyword));
        qDebug() << baseUrl;
    
        // declare arguments
        curlArguements << "-s"
                        << baseUrl.toString();
    
        perlArguments <<  dbpediaPlaceFile <<" " << mKeyword;
    
        _timer = new QTimer();
        _timer->setInterval(100);
    
        connect(_timer, &QTimer::timeout, this, QOverload<>::of(&ProcessManager::start_process));
    
    }
    
    bool ProcessManager::start_process(QString name)
    {
        // Use resizable buffers, unlike the system.
       QByteArray byteerr;
       QByteArray byteout;
    
     QString dbpediaPlaceFile = "dbpediaPlaceFile.txt";
    
        curlProcess->start("curl", {"-s", "http://dbpedia.org/data/Haeinsa.json"});
    
        if (curlProcess->waitForFinished(-1))
         {
            // perlProcess->setProcessChannelMode(QProcess::ForwardedChannels);
             perlProcess->start("perl",  { dbpediaPlaceFile, "Haeinsa"});
    
             QByteArray byteData = curlProcess->readAll();
              perlProcess->write(byteData);
             perlProcess->closeWriteChannel();
    
         perlProcess->waitForStarted();
    
         do {
                 
             byteerr += perlProcess->readAllStandardError();
             byteout += perlProcess->readAllStandardOutput();
    
             qDebug() << byteerr;
             qDebug() << byteout;
         }
             // Wait 100 ms and keep looping if not finished.
         while ( !perlProcess->waitForFinished(1000) );
    
             // Make sure you catch any leftovers.
         byteerr += perlProcess->readAllStandardError();
         byteout += perlProcess->readAllStandardOutput();
    
         qDebug() << byteerr;
         qDebug() << byteout;
    
         }
    
     //_timer->stop();
    }
    

    [Locked as duplicate ~kshegunov]



  • @darongyi

    AFAIK I have seen this post already this morning.

    Now it seemed to be gone. Please do not delete a post and repost for catching attention.




  • Qt Champions 2019

    @darongyi This is already third thread with same question! Why?


Log in to reply