void YTVideoUrlFetcher::onFetchUrlsFor(QString videoId) { Q_ASSERT(!_process); qDebug() << "Trying to obtain video urls for:" << videoId; if (_response_cache.contains(videoId)) { qDebug() << "Response for" << videoId << "available in cache, using it"; QVariantMap response = *_response_cache[videoId]; emit success(response); return; } QStringList arguments; arguments << "--dump-json" << "--youtube-skip-dash-manifest" << "--no-cache-dir" << "--no-call-home" << "https://www.youtube.com/watch?v=" + videoId; qDebug() << "YouTubeDL subprocess:" << getYouTubeDLPath() << arguments; _process = new QProcess(0); connect(_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onProcessFinished(int, QProcess::ExitStatus))); connect(_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onProcessError(QProcess::ProcessError))); _process->start(getYouTubeDLPath(), arguments, QIODevice::ReadOnly); }
// ---------------------------------------------------------------------------- void LocalEvaluator::createProcess() { process = new QProcess(this); process->setProcessChannelMode(QProcess::MergedChannels); connect( process, SIGNAL( error(QProcess::ProcessError) ), SLOT( onProcessError(QProcess::ProcessError) ) ); connect( process, SIGNAL( readyRead() ), SLOT( onProcessOutput() ) ); connect( process, SIGNAL( finished(int) ), SLOT( exit(int) ) ); }
// ---------------------------------------------------------------------------- void LocalEvaluator::reset() { //setWorkingDir( "" ); disconnect( process, SIGNAL( error(QProcess::ProcessError) ), this, SLOT( onProcessError(QProcess::ProcessError) ) ); disconnect( process, SIGNAL( readyRead() ), this, SLOT( onProcessOutput() ) ); disconnect( process, SIGNAL( finished(int) ), this, SLOT( exit(int) ) ); kill(); process->deleteLater(); createProcess(); startJulia(); }
ProcessHandler::ProcessHandler(AppInstance* app, const QString& projectPath, Natron::OutputEffectInstance* writer) : _app(app) ,_process(new QProcess) ,_writer(writer) ,_ipcServer(0) ,_bgProcessOutputSocket(0) ,_bgProcessInputSocket(0) ,_earlyCancel(false) ,_processLog() { ///setup the server used to listen the output of the background process _ipcServer = new QLocalServer(); QObject::connect(_ipcServer,SIGNAL(newConnection()),this,SLOT(onNewConnectionPending())); QString serverName; int randomNumber = std::rand(); { QTemporaryFile tmpf(NATRON_APPLICATION_NAME "_OUTPUT_PIPE_" + QString::number(randomNumber)); tmpf.open(); serverName = tmpf.fileName(); tmpf.remove(); } _ipcServer->listen(serverName); QStringList processArgs; processArgs << projectPath << "-b" << "-w" << writer->getName().c_str(); processArgs << "--IPCpipe" << (_ipcServer->fullServerName()); ///connect the useful slots of the process QObject::connect(_process,SIGNAL(readyReadStandardOutput()),this,SLOT(onStandardOutputBytesWritten())); QObject::connect(_process,SIGNAL(readyReadStandardError()),this,SLOT(onStandardErrorBytesWritten())); QObject::connect(_process,SIGNAL(error(QProcess::ProcessError)),this,SLOT(onProcessError(QProcess::ProcessError))); QObject::connect(_process,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(onProcessEnd(int,QProcess::ExitStatus))); ///start the process _processLog.push_back("Starting background rendering: " + QCoreApplication::applicationFilePath()); _processLog.push_back(" "); for (int i = 0; i < processArgs.size(); ++i) { _processLog.push_back(processArgs[i] + " "); } _process->start(QCoreApplication::applicationFilePath(),processArgs); }
void CXUtilsWindow::onExecute() { QTreeWidgetItem* curItem = mTreeWidget->currentItem(); if (curItem != NULL) { QString command = curItem->data(0, Qt::UserRole + 100).toString(); mProcess = new CXProcess(this); connect(mProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onProcessFinish(int, QProcess::ExitStatus))); connect(mProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onProcessError(QProcess::ProcessError))); mBox = new QMessageBox(QMessageBox::Information,trUtf8("Идет отработка"),trUtf8("\tПрервать\t"),QMessageBox::Ok,this); mBox->setMinimumWidth(600); mBox->show(); mProcess->start(command); }
ProcessHandler::ProcessHandler(const QString & projectPath, const NodePtr& writer) : _process(new QProcess) , _writer(writer) , _ipcServer(0) , _bgProcessOutputSocket(0) , _bgProcessInputSocket(0) , _earlyCancel(false) , _processLog() , _processArgs() { ///setup the server used to listen the output of the background process _ipcServer = new QLocalServer(); QObject::connect( _ipcServer, SIGNAL(newConnection()), this, SLOT(onNewConnectionPending()) ); QString tmpFileName; #if defined(Q_OS_WIN) tmpFileName += QString::fromUtf8("//./pipe"); tmpFileName += QLatin1Char('/'); tmpFileName += QString::fromUtf8(NATRON_APPLICATION_NAME); tmpFileName += QString::fromUtf8("_INPUT_SOCKET"); #endif { #if defined(Q_OS_UNIX) QTemporaryFile tmpf(tmpFileName); tmpf.open(); tmpFileName = tmpf.fileName(); tmpf.remove(); #else QTemporaryFile tmpf; tmpf.open(); QString tmpFilePath = tmpf.fileName(); QString baseName; int lastSlash = tmpFilePath.lastIndexOf( QLatin1Char('/') ); if ( (lastSlash != -1) && (lastSlash < tmpFilePath.size() - 1) ) { baseName = tmpFilePath.mid(lastSlash + 1); } else { baseName = tmpFilePath; } tmpFileName += baseName; tmpf.remove(); #endif } _ipcServer->listen(tmpFileName); _processArgs << QString::fromUtf8("-b") << QString::fromUtf8("-w") << QString::fromUtf8( writer->getScriptName_mt_safe().c_str() ); _processArgs << QString::fromUtf8("--IPCpipe") << tmpFileName; _processArgs << projectPath; ///connect the useful slots of the process QObject::connect( _process, SIGNAL(readyReadStandardOutput()), this, SLOT(onStandardOutputBytesWritten()) ); QObject::connect( _process, SIGNAL(readyReadStandardError()), this, SLOT(onStandardErrorBytesWritten()) ); QObject::connect( _process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onProcessError(QProcess::ProcessError)) ); QObject::connect( _process, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(onProcessEnd(int,QProcess::ExitStatus)) ); ///start the process _processLog.push_back( tr("Starting background rendering: %1 %2") .arg( QCoreApplication::applicationFilePath() ) .arg( _processArgs.join( QString::fromUtf8(" ") ) ) ); }