Command working in terminal but not via QProcess
Solved
General and Desktop
-
I am currently using macOS Sierra and QT 5.8. This command
git rev-list --count branchname
is working when executed via terminal. But not via QProcess.
My sample code isQSharedPointer<QProcess> proc(new QProcess); proc->start("git", QStringList() << "rev-list" << "--count" << "branchname"); proc->waitForFinished(); QByteArray output = proc->readAll(); proc->close(); qDebug() << output;
So, after execute the code above, the console output is empty.
What might be the problem?
-
@keytooker Rough guess. Which folder is it executing in? Run the "pwd" command to find out.
-
@keytooker said in Command working in terminal but not via QProcess:
QProcess
Hi
Hook up error handler and see what it reportsconnect(proc, &QProcess::errorOccurred, [=](QProcess::ProcessError error) { qDebug() << "error enum val = " << error << endl; });
-
@matthew.kuiash Thank you for your hint! Shadow build is "on" in my project . Therefore the git-command was executed in other directory. I have corrected my code here so:
auto oldPath = QDir::currentPath(); QString sourcePath = QStringLiteral("/Users/user_name/project_source_directory"); if (QDir::setCurrent(sourcePath)) { proc->start("git", QStringList() << "rev-list" << "--count" << "branch_name"); proc->waitForFinished(); QByteArray output = proc->readAll(); proc->close(); qDebug() << output; } QDir::setCurrent(oldPath);