void ChildForm::runProcess() { RunProcessDialog rpd(this); // If the process failed to start, then it // cannot be deleted from the processError call // because it may be called from within the call to // _proc->start()... so _proc cannot be deleted... if ((_proc != nullptr) && (_procError == true)) { deleteProcess(); } if (_proc == nullptr) { if (rpd.exec() == RunProcessDialog::Accepted) { _procError = false; _redirectStdout = rpd.isStdoutRedirected(); _redirectStderr = rpd.isStderrRedirected(); _proc = new QProcess(this); connect(_proc, SIGNAL(readyReadStandardOutput()), this, SLOT(readFromStdout())); connect(_proc, SIGNAL(readyReadStandardError()), this, SLOT(readFromStderr())); connect(_proc, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError))); connect(_proc, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processDone(int,QProcess::ExitStatus))); _proc->setWorkingDirectory(rpd.getWorkingDirectory()); QStringList args = rpd.getArguments(); suppressOutput(rpd.isOutputSuppressed()); MainWindow::getMainWindow()->swapProcessIcon(true); _proc->start(rpd.getProgram(), args); } }
void TgtProcessIntf::tgtMakeConnection() { std::shared_ptr<const TgtConnectionConfig> connectionConfig = std::dynamic_pointer_cast<const TgtConnectionConfig>( _connectionConfig); _proc = new QProcess(this); connect(_proc, SIGNAL(readyReadStandardOutput()), this, SLOT(readFromStdout())); connect(_proc, SIGNAL(readyReadStandardError()), this, SLOT(readFromStderr())); connect(_proc, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError))); connect(_proc, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processDone(int,QProcess::ExitStatus))); _proc->setWorkingDirectory(connectionConfig->_workingDir.c_str()); QStringList args(connectionConfig->_args.c_str()); QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); env.insert("TERM", "xterm"); env.insert("COLORTERM", "gnome-terminal"); _proc->setProcessEnvironment(env); _proc->start(connectionConfig->_program.c_str(), args); _processWriterThread = TgtThread::create(boost::protect(std::bind(&TgtProcessIntf::writerThread, this))); }
/*! \internal */ bool QProcessPrivate::canReadStandardError() { Q_Q(QProcess); qint64 available = bytesAvailableFromStderr(); if (available == 0) { if (errorReadSocketNotifier) errorReadSocketNotifier->setEnabled(false); destroyPipe(errorReadPipe); return false; } char *ptr = errorReadBuffer.reserve(available); qint64 readBytes = readFromStderr(ptr, available); if (readBytes == -1) { processError = QProcess::ReadError; q->setErrorString(QT_TRANSLATE_NOOP(QProcess, QLatin1String("Error reading from process"))); emit q->error(processError); return false; } if (standardErrorClosed) { errorReadBuffer.truncate(readBytes); return false; } errorReadBuffer.truncate(available - readBytes); bool didRead = false; if (readBytes == 0) { if (errorReadSocketNotifier) errorReadSocketNotifier->setEnabled(false); } else if (processChannel == QProcess::StandardError) { didRead = true; if (!emittedReadyRead) { emittedReadyRead = true; emit q->readyRead(); emittedReadyRead = false; } } emit q->readyReadStandardError(); return didRead; }
CommandManager::CommandManager(QWidget * parent, const char * name, const QStringList & args ) : QDialog( parent) { EndMessage = "\n\n EXECUTION COMPLETED ! ! ! "; // default // Layout setFixedSize ( 550, 500 ) ; //setCaption( name ); setWindowTitle(name); //qt3to4 -- BW //output = new Q3TextEdit( this ); output = new QTextEdit( this ); output->setReadOnly( true ); output->setGeometry( QRect( 20, 20, 510, 430 ) ); //qt3to4 -- BW //output->setHScrollBarMode ( Q3ScrollView::Auto ); output->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); //output->setWordWrap( Q3TextEdit::NoWrap ); output->setWordWrapMode(QTextOption::NoWrap); // output->setTextFormat( Qt::RichText ); quitButton = new QPushButton( tr("&Close"), this ); quitButton->move(390, 465); connect( quitButton, SIGNAL(clicked()), this, SLOT(close()) ); quitButton->setEnabled( false ); killButton = new QPushButton( tr("&Kill"), this ); killButton->move(270, 465); connect( killButton, SIGNAL(clicked()), this, SLOT(killProcess()) ); // QProcess related code //qt3to4 -- BW //proc = new Q3Process( this ); proc = new QProcess( this ); //proc->clearArguments(); // Set up the command and arguments. //qt3to4 -- BW //proc->setArguments ( args ); //proc->setCommunication(QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr); connect( proc, SIGNAL(readyReadStandardOutput()), this, SLOT(readFromStdout()) ); connect( proc, SIGNAL(readyReadStandardError()), this, SLOT(readFromStderr()) ); connect( proc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(scrollToTop()) ); // output->setText( (QString)"<u>EXECUTING :</u>"+args.join( " " ) ); //qt3to4 -- BW //output->insert( (QString)"EXECUTING : "+args.join( " " ) +(QString)"\n", // (uint)Q3TextEdit::CheckNewLines | Q3TextEdit::RemoveSelected ); output->insertPlainText( (QString)"EXECUTING : "+args.join( " " ) +(QString)"\n"); //qt3to4 -- BW QString prog = args.first(); QStringList args2 = args.mid(1); proc->start(prog,args2); //qt3to4 -- BW //if ( !proc->start() ) { if(proc->error()==QProcess::FailedToStart) { // error handling //QString errorM = "Could not start the command: \n" +args.join( "\n" ); QString errorM = args.join( "\n" ); QMessageBox::critical( 0, tr("Fatal error"), tr("Could not start the command: \ni %1").arg(errorM), tr("Quit") ); //exit( -1 ); } }