本文整理汇总了C++中QProcess::setStandardOutputFile方法的典型用法代码示例。如果您正苦于以下问题:C++ QProcess::setStandardOutputFile方法的具体用法?C++ QProcess::setStandardOutputFile怎么用?C++ QProcess::setStandardOutputFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QProcess
的用法示例。
在下文中一共展示了QProcess::setStandardOutputFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: System
int System(const QString exename, const QStringList & args, const QString fileStdErr, const QString fileStdOut, bool* cancel)
{
QProcess proc;
if (!fileStdOut.isEmpty())
proc.setStandardOutputFile(fileStdOut);
if (!fileStdErr.isEmpty())
proc.setStandardErrorFile(fileStdErr);
proc.start(exename, args);
if (proc.waitForStarted(5000))
{
while (!proc.waitForFinished(5000))
{
qApp->processEvents();
if (cancel && (*cancel == true))
{
proc.kill();
break;
}
}
}
if (cancel && (*cancel == true))
return -1;
int ex = proc.exitCode();
return ex;
}
示例2: on_runButton_clicked
void Widget::on_runButton_clicked()
{
QProcess *process = new QProcess();
QString filename = "";
if(ui->fileNameEdit->text() == ""){
filename = "sca_" + QDateTime::currentDateTime().toString("yyyy_MM_dd_hh_mm") + getOptions();
}else{
filename = ui->fileNameEdit->text();
}
process->setStandardOutputFile(filename);
QString command = "clang-tidy -extra-arg=\"-std=c++11\"" + getConfig() + " -checks='-*,misc-suspicious-call-argument' " + ui->pathEdit->text() + " --";
//process->setWorkingDirectory("/home/varjujan/Asztal");
process->start("/bin/bash", QStringList() << "-c" << command);
process->waitForFinished();
process->close();
ui->textBrowser->setText(command);
process = new QProcess();
process->start("gedit", QStringList() << filename);
process->waitForStarted();
//process->close();
}
示例3: loadImage
// Load image data
QImage ExternalImageLoader::loadImage()
{
QImage result;
// Configuration file loading
QSettings settings("../res/externalimageloader.ini", QSettings::IniFormat);
// Get external program, redirection and result file names
QString program = settings.value("program").toString();
QString redirection = settings.value("redirection").toString();
QString filename = settings.value("filename").toString();
if (program.isEmpty() || filename.isEmpty())
return result;
// Ensure program has started
QProcess process;
if (!redirection.isEmpty())
process.setStandardOutputFile(redirection);
process.start(program);
if (!process.waitForStarted())
return result;
// Get timeout value
int timeout = settings.value("timeout").toInt();
QTime timer;
timer.start();
// Check for program exit or timeout event
while (process.state() != QProcess::NotRunning)
{
if (timeout > 0 && timer.elapsed() > timeout)
{
// Stop process
process.kill();
// Try to delete file
QDir dir;
dir.remove(filename);
// Return null image
return result;
}
qApp->processEvents();
}
// Ensure program has finished correctly
if (process.exitStatus() != QProcess::NormalExit)
return result;
// Try to read and remove the output file
result = QImage(filename);
QDir dir;
dir.remove(filename);
return result;
}
示例4: createProcess
QProcess* Runtime::createProcess()
{
QProcess* process = new QProcess();
QString logFile = this->logsDir + QString("/") + QDate::currentDate().toString() + QString("_log.txt");
process->setStandardErrorFile(logFile, QIODevice::Append);
process->setStandardOutputFile(logFile, QIODevice::Append);
return process;
}
示例5: startProcess
void LSession::startProcess(QString ID, QString command){
QString logfile = QDir::homePath()+"/.lumina/logs/"+ID+".log";
if(QFile::exists(logfile+".old")){ QFile::remove(logfile+".old"); }
if(QFile::exists(logfile)){ QFile::rename(logfile,logfile+".old"); }
QProcess *proc = new QProcess();
proc->setProcessChannelMode(QProcess::MergedChannels);
proc->setProcessEnvironment( QProcessEnvironment::systemEnvironment() );
proc->setStandardOutputFile(logfile);
proc->start(command, QIODevice::ReadOnly);
connect(proc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(procFinished()) );
PROCS << proc;
}
示例6: save
bool PdmlFileFormat::save(const OstProto::StreamConfigList streams,
const QString fileName, QString &error)
{
bool isOk = false;
QTemporaryFile pcapFile;
StreamFileFormat *fmt = StreamFileFormat::fileFormatFromType("PCAP");
QProcess tshark;
Q_ASSERT(fmt);
if (!pcapFile.open())
{
error.append("Unable to open temporary file to create PCAP\n");
goto _fail;
}
qDebug("intermediate PCAP %s", pcapFile.fileName().toAscii().constData());
connect(fmt, SIGNAL(target(int)), this, SIGNAL(target(int)));
connect(fmt, SIGNAL(progress(int)), this, SIGNAL(progress(int)));
emit status("Writing intermediate PCAP file...");
isOk = fmt->save(streams, pcapFile.fileName(), error);
qDebug("generating PDML %s", fileName.toAscii().constData());
emit status("Converting PCAP to PDML...");
emit target(0);
tshark.setStandardOutputFile(fileName);
tshark.start(OstProtoLib::tsharkPath(),
QStringList()
<< QString("-r%1").arg(pcapFile.fileName())
<< "-Tpdml");
if (!tshark.waitForStarted(-1))
{
error.append(QString("Unable to start tshark. Check path in preferences.\n"));
goto _fail;
}
if (!tshark.waitForFinished(-1))
{
error.append(QString("Error running tshark\n"));
goto _fail;
}
isOk = true;
_fail:
return isOk;
}
示例7: enregistrer
void detailwnd::enregistrer( )
{
QString destFile = QFileDialog::getSaveFileName(this, tr("Sauver la video"),
"/home/dige7306/"+leAdresse->text(),
tr("Video (*.asf *.asx *.wsx *.wmv *.flv *.avi)"));
if ( destFile.isEmpty() ) return;
QStringList arg;
/* for eurosport
arg << "-cache";
arg << "4096";
arg << "-dumpstream";
arg << "-dumpfile";
arg << destFile;
arg << leAdresse->text();
QProcess::execute( "mplayer", arg );
arg.clear();
arg << "/usr/share/sounds/k3b_success1.wav";
QProcess::execute( "mplayer", arg );
*/
/* for atdhe.net */
arg << leAdresse->text();
QProcess::execute( "firefox", arg );
sleep( 5 ); /* wait for plugin to start */
QStringList f;
f << "Flash*";
QStringList files = QDir::temp().entryList( f );
qDebug() << files[0];
arg.clear();
arg << "-n" << "100000" << "--follow=name" << QDir::tempPath() + "/" + files[0];
QProcess *tail = new QProcess( this );
tail->setStandardOutputFile( destFile, QIODevice::Truncate );
tail->setStandardErrorFile( "/tmp/tail.err", QIODevice::Truncate );
tail->start( "tail", arg );
if ( tail->waitForStarted() )
{
int msec = teDuree->time().hour() * 60 * 60 + teDuree->time().minute() * 60;
msec *= 1000;
if ( msec == 0 ) msec = -1;
if ( !tail->waitForFinished(msec) )
{
tail->terminate();
}
qDebug() << " tail : " << tail->exitStatus() << " " << tail->exitCode() << endl;
}
else
{
qDebug() << " tail non demarre" << endl;
}
}
示例8: startProcess
void LSession::startProcess(QString ID, QString command){
QString dir = QString(getenv("XDG_CONFIG_HOME"))+"/lumina-desktop/logs";
if(!QFile::exists(dir)){ QDir tmp(dir); tmp.mkpath(dir); }
QString logfile = dir+"/"+ID+".log";
if(QFile::exists(logfile+".old")){ QFile::remove(logfile+".old"); }
if(QFile::exists(logfile)){ QFile::rename(logfile,logfile+".old"); }
QProcess *proc = new QProcess();
proc->setProcessChannelMode(QProcess::MergedChannels);
proc->setProcessEnvironment( QProcessEnvironment::systemEnvironment() );
proc->setStandardOutputFile(logfile);
proc->start(command, QIODevice::ReadOnly);
connect(proc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(procFinished()) );
PROCS << proc;
}
示例9: on_btnScan_clicked
void ScannerDialog::on_btnScan_clicked()
{
#ifdef Q_OS_LINUX
ui->btnTest->setEnabled(false);
ui->btnScan->setEnabled(false);
ui->btnAnnuler->setEnabled(false);
QProcess* process = new QProcess();
process->setStandardOutputFile(QDir::tempPath() + "/output.pnm");
process->start("scanimage --resolution 200");
ui->progressBar->show();
connect(process, SIGNAL(finished(int)), SLOT(scanFinished(int)));
#endif
}
示例10: changeDir
QString Repository::Git::GitUtils::makeTmpFileFromCommand( QString command, QString filepath )
{
bool ok = true;
// Ulozim si current working directory
QString cwd = QDir::currentPath();
// Nastavim absolutnu cestu k temp file ako template a zakazem automaticke mazanie
QTemporaryFile tempFile;
tempFile.setFileTemplate( QDir::toNativeSeparators( QDir::tempPath() + "/" + "qXXXXXX" ) );
tempFile.setAutoRemove( false );
// Ak sa nepodarilo vytvorit temp subor, tak nastavim flag "ok" na false a vypisem chybu
if ( !tempFile.open() ) {
qDebug() << "Nepodarilo sa vytvorit tmp subor";
ok = false;
}
// Ak sa podarilo vytvorit temp subor, tak zmenim current working directory
if ( ok ) {
ok = changeDir( filepath );
}
// Ak sa podarilo zmenit current working directory, tak skontroluje existenciu git repozitara
if ( ok ) {
ok = existGit( filepath );
}
// Ak existuje na danej ceste git repozitar, tak vykonam command a vystup ulozim do temp suboru
if ( ok ) {
QProcess process;
process.setStandardOutputFile( QDir::toNativeSeparators( tempFile.fileName() ) );
process.start( command );
process.waitForFinished();
process.close();
process.terminate();
}
// Vratim povodny current working directory, ak sa nepodari zmenit, vypisem do konzoly
if ( !changeDir( cwd ) ) {
qDebug() << "Nepodarilo sa vratit na povodny current working directory";
}
// Vratim absolutnu cestu k temp suboru
return tempFile.fileName();
}
示例11: RunApp
static QString RunApp(const QString &execPath, const QString &execParam, const QString &execPipeIn="") {
QString outPipePath = Xapi::TmpFilePath("pipeOut");
QProcess app;
app.setStandardInputFile(execPipeIn);
app.setStandardOutputFile(outPipePath);
app.setStandardErrorFile(outPipePath);
app.start(execPath + " " + execParam);
app.waitForFinished();
if (QProcess::NormalExit != app.exitStatus())
qDebug()<<app.error()<<app.errorString()<<app.state();
QFile locale(outPipePath);
if (!locale.open(QIODevice::ReadOnly)) {
qDebug()<<"Open output pipe Fialed!"<<outPipePath;
return "";
}
QTextStream localets(&locale);
QString outUtf8PipePath = Xapi::TmpFilePath("utf8pipeOut");
QFile utf8(outUtf8PipePath);
if (!utf8.open(QIODevice::WriteOnly)) {
qDebug()<<"Open utf8 output pipe Fialed!"<<outUtf8PipePath;
return "";
}
QTextStream utf8ts(&utf8);
utf8ts.setCodec("utf8");
utf8ts<<localets.readAll();
locale.close();
utf8.close();
utf8.open(QIODevice::ReadOnly);
QString ret = QString(utf8.readAll());
utf8.close();
locale.remove();
utf8.remove();
return ret;
}
示例12: executeCommand
void executeCommand(const QString &command, const QStringList &arguments, const QString &outputFile,
bool verbose)
{
QTextStream out(stderr);
if (command.isEmpty()) {
out << "Error: " << Q_FUNC_INFO << "Got empty command to execute." << endl;
exit(EXIT_FAILURE);
}
const QString fullCommand = command + QLatin1Char(' ') + arguments.join(QLatin1Char(' '));
if (verbose)
out << "Executing: " << fullCommand << endl;
QProcess process;
if (!outputFile.isEmpty())
process.setStandardOutputFile(outputFile, QIODevice::Truncate);
process.start(command, arguments);
if (!process.waitForStarted()) {
out << QString::fromLatin1("Error: Process \"%1\" did not start within timeout: %2.")
.arg(fullCommand, process.errorString())
<< endl;
exit(EXIT_FAILURE);
}
if (!process.waitForFinished()) {
if (!verbose)
out << process.readAll() << endl;
out << QString::fromLatin1("Error: Process \"%1\" did not finish within timeout.")
.arg(fullCommand)
<< endl;
exit(EXIT_FAILURE);
}
const int exitCode = process.exitCode();
if (exitCode != 0) {
out << process.readAllStandardError() << endl;
out << QString::fromLatin1("Error: Process \"%1\" finished with non zero exit value %2")
.arg(fullCommand, exitCode) << endl;
exit(EXIT_FAILURE);
}
}
示例13: start
void SqliteProcess::start(const QStringList & commands, const QStringList & options)
{
QProcess p;
if (!m_stdout.isNull())
p.setStandardOutputFile(m_stdout);
QStringList list = QStringList() << options << m_mainDbPath << commands;
qDebug() << "Running " << SQLITE_BINARY << " with args: " << list;
qDebug() << QString(" %1 %2").arg(SQLITE_BINARY).arg(list.join(" "));
p.start(SQLITE_BINARY, list);
if (!p.waitForStarted() || !p.waitForFinished(-1) || (p.exitStatus() != QProcess::NormalExit))
{
m_success = false;
switch (p.error())
{
case (QProcess::FailedToStart) :
m_error = tr("The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.");
break;
case (QProcess::Crashed) :
m_error = tr("The process crashed some time after starting successfully.");
break;
case (QProcess::WriteError) :
m_error = tr("An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel.");
break;
case (QProcess::ReadError):
m_error = tr("An error occurred when attempting to read from the process. For example, the process may not be running.");
break;
default:
m_error = tr("An unknown error occurred.");
}
}
else
m_success = true;
m_stderr = QString(p.readAllStandardError());
m_stdout = QString(p.readAllStandardOutput());
}
示例14: getExecutionOutput
QString getExecutionOutput(const QString& cmd, const QStringList& args)
{
QProcess p;
p.setStandardOutputFile(QDir::temp().filePath(QString().sprintf("adb-state-repair-center.%lx", long(QThread::currentThreadId()))));
p.setStandardErrorFile(QDir::temp().filePath(QString().sprintf("adb-state-repair-center.%lx", long(QThread::currentThreadId()))));
p.start(cmd, args);
if (!p.waitForFinished(-1)) {
p.kill();
p.waitForFinished();
} else {
QFile result(QDir::temp().filePath(QString().sprintf("adb-state-repair-center.%lx", long(QThread::currentThreadId()))));
result.open(QIODevice::ReadOnly);
QString ret = result.readAll();
ret.replace("\r", "");
while (ret.endsWith("\n")) {
ret.chop(1);
}
result.close();
result.remove();
return ret;
}
return "";
}
示例15: startServer
bool MOomc::startServer()
{
try
{
// evalMutex.unlock();
QString msg;
const char *omhome = getenv("OPENMODELICAHOME");
QString omcPath;
#ifdef WIN32
if (!omhome)
{
InfoSender::instance()->send(Info("OPEN_MODELICA_HOME_NOT_FOUND"));
return false;
}
omcPath = QString( omhome ) + "bin/omc.exe";
#else /* unix */
omcPath = (omhome ? QString(omhome)+"bin/omc" : QString(CONFIG_DEFAULT_OPENMODELICAHOME) + "/bin/omc");
#endif
// Check the IOR file created by omc.exe
QFile objectRefFile;
QString fileIdentifier;
fileIdentifier = qApp->sessionId().append(QTime::currentTime().toString(tr("hh:mm:ss:zzz")).remove(":"));
#ifdef WIN32 // Win32
objectRefFile.setFileName(QString(QDir::tempPath()).append(QDir::separator()).append("openmodelica.objid.").append(this->mName).append(fileIdentifier));
#else // UNIX environment
char *user = getenv("USER");
if (!user) { user = "nobody"; }
objectRefFile.setFileName(QString(QDir::tempPath()).append(QDir::separator()).append("openmodelica.").append(QString(user)).append(".objid.").append(this->mName).append(fileIdentifier));
#endif
if (objectRefFile.exists())
objectRefFile.remove();
mObjectRefFile = objectRefFile.fileName();
// Start the omc.exe
QStringList parameters;
parameters << QString("+c=").append(mName).append(fileIdentifier) << QString("+d=interactiveCorba") << QString("+corbaObjectReferenceFilePath=").append(QDir::tempPath());
QProcess *omcProcess = new QProcess();
QFile omcOutputFile;
#ifdef WIN32 // Win32
omcOutputFile.setFileName(QString(QDir::tempPath()).append(QDir::separator()).append("openmodelica.omc.output.").append(mName));
#else // UNIX environment
omcOutputFile.setFileName(QString(QDir::tempPath()).append(QDir::separator()).append("openmodelica.").append(( QString(user))).append(".omc.output.").append(mName));
#endif
omcProcess->setProcessChannelMode(QProcess::MergedChannels);
omcProcess->setStandardOutputFile(omcOutputFile.fileName());
omcProcess->start(omcPath, parameters);
// wait for the server to start.
int ticks = 0;
while (!objectRefFile.exists())
{
SleeperThread::msleep(1000);
ticks++;
if (ticks > 20)
{
msg = "Unable to find " + OMCHelper::applicationName + " server, Object reference file " + mObjectRefFile + " not created.";
throw std::runtime_error(msg.toStdString());
}
}
// ORB initialization.
int argc = 2;
static const char *argv[] = { "-ORBgiopMaxMsgSize", "10485760" };
CORBA::ORB_var orb = CORBA::ORB_init(argc, (char **)argv);
objectRefFile.open(QIODevice::ReadOnly);
char buf[1024];
objectRefFile.readLine( buf, sizeof(buf) );
QString uri( (const char*)buf );
CORBA::Object_var obj = orb->string_to_object(uri.trimmed().toLatin1());
mOMC = OmcCommunication::_narrow(obj);
mHasInitialized = true;
}
catch(std::exception &e)
{
QString msg = e.what();
InfoSender::instance()->send(Info(msg,ListInfo::ERROR2));
mHasInitialized = false;
return false;
}
catch (CORBA::Exception&)
{
QString msg = "Unable to communicate with OMC";
InfoSender::instance()->send(Info(msg,ListInfo::ERROR2));
mHasInitialized = false;
return false;
}
evalCommand("getInstallationDirectoryPath()");
OMCHelper::OpenModelicaHome = StringHandler::removeFirstLastQuotes(getResult());
initTempDirectory();
//.........这里部分代码省略.........