Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Command working in terminal but not via QProcess

Command working in terminal but not via QProcess

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 851 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    keytooker
    wrote on last edited by
    #1

    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 is

    QSharedPointer<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?

    matthew.kuiashM 1 Reply Last reply
    0
    • K keytooker

      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 is

      QSharedPointer<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?

      matthew.kuiashM Offline
      matthew.kuiashM Offline
      matthew.kuiash
      wrote on last edited by
      #2

      @keytooker Rough guess. Which folder is it executing in? Run the "pwd" command to find out.

      The legendary cellist Pablo Casals was asked why he continued to practice at age 90. "Because I think I'm making progress," he replied.

      K 1 Reply Last reply
      1
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @keytooker said in Command working in terminal but not via QProcess:

        QProcess

        Hi
        Hook up error handler and see what it reports

        connect(proc, &QProcess::errorOccurred, [=](QProcess::ProcessError error) 
        { 
            qDebug() << "error enum val = " << error << endl; 
        });
        
        1 Reply Last reply
        2
        • matthew.kuiashM matthew.kuiash

          @keytooker Rough guess. Which folder is it executing in? Run the "pwd" command to find out.

          K Offline
          K Offline
          keytooker
          wrote on last edited by
          #4

          @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);
          
          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved