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. Can't launch simple command with qprocess
Qt 6.11 is out! See what's new in the release blog

Can't launch simple command with qprocess

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 426 Views 2 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.
  • R Offline
    R Offline
    roy942
    wrote on last edited by
    #1

    Hi,

    I'm trying to launch a console command via qprocess but execute always return -2 (process can't start i mean). My purpose is more complicated but the simple code below do nothing:

    QProcess gitProcess;
    gitProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
    gitProcess.setWorkingDirectory(QString::fromLatin1(a_args.workingDirectory));
    int iRet = gitProcess.execute("mkdir test");
    

    I don't understand what I do wrong.

    Thanks.
    (sorry for my english)

    J.HilkJ 1 Reply Last reply
    0
    • R roy942

      Hi,

      I'm trying to launch a console command via qprocess but execute always return -2 (process can't start i mean). My purpose is more complicated but the simple code below do nothing:

      QProcess gitProcess;
      gitProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
      gitProcess.setWorkingDirectory(QString::fromLatin1(a_args.workingDirectory));
      int iRet = gitProcess.execute("mkdir test");
      

      I don't understand what I do wrong.

      Thanks.
      (sorry for my english)

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @roy942

      first of, you need to realise QProcess is not a terminal/shell/commandprompt .

      but you can launch one with it and have that one execute your mkdir command:

      I assume Windows(?)

          QProcess Process;
          QObject::connect(&Process, &QProcess::errorOccurred, &app, [](QProcess::ProcessError error)->void{qDebug() << error;});
          Process.start("cmd.exe", QStringList() << "/C" <<"mkdir"<< "test");
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

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

        Hi
        mkdir is not an .exe file but a build-in command and hence you can't just start it and has to start it via
        cmd.exe as J-Hilk shows.

        1 Reply Last reply
        2
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Or more cross-platform: QDir::mkdir.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          4

          • Login

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