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. QT - create CMD and execute .bat file
Forum Update on Monday, May 27th 2025

QT - create CMD and execute .bat file

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 7.2k Views
  • 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.
  • T Offline
    T Offline
    TryToQT
    wrote on last edited by
    #1

    Hi Guys, i am new in developing with QT and i have problems by starting a .bat file, do i need to start a cmd.exe and start there my .bat file or is there an easy way to execute it. Maybe someone has an hint for me, thanks
    I tried it like that:
    QStringList arguments;
    arguments << "/c C:/Program Files (x86)/test/test.bat ";
    QProcess exec;
    exec.start("C:/WINDOWS/system32/cmd.exe", arguments);
    exec.waitForFinished();

    raven-worxR 1 Reply Last reply
    0
    • T TryToQT

      Hi Guys, i am new in developing with QT and i have problems by starting a .bat file, do i need to start a cmd.exe and start there my .bat file or is there an easy way to execute it. Maybe someone has an hint for me, thanks
      I tried it like that:
      QStringList arguments;
      arguments << "/c C:/Program Files (x86)/test/test.bat ";
      QProcess exec;
      exec.start("C:/WINDOWS/system32/cmd.exe", arguments);
      exec.waitForFinished();

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @TryToQT said in QT - create CMD and execute .bat file:

      QStringList arguments;
      arguments << "/c C:/Program Files (x86)/test/test.bat ";
      QProcess exec;
      exec.start("C:/WINDOWS/system32/cmd.exe", arguments);

      should be:

      QStringList arguments;
          arguments << "/c" << "\"C:\\Program Files (x86)\\test\\test.bat\"";
      QProcess exec;
          exec.start("cmd.exe", arguments);
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      4
      • T Offline
        T Offline
        TryToQT
        wrote on last edited by
        #3

        thank you for your reply, but the .bat wasn't executed after these lines, any ideas which i can try instead

        Taz742T 1 Reply Last reply
        0
        • artwawA Offline
          artwawA Offline
          artwaw
          wrote on last edited by
          #4

          Hi,
          why don't you check (after process fails to start) QProcess::error() method?

          From top of my head I would first try to not use backslash "" but just used regular slash "/" instead. It may sound silly but works under Windows and you have less characters to escape.
          Secondly, you can use start() with single QString parameter that has all the parameters - worth trying that way.
          And check QProcess::error() for result.

          For more information please re-read.

          Kind Regards,
          Artur

          1 Reply Last reply
          2
          • T TryToQT

            thank you for your reply, but the .bat wasn't executed after these lines, any ideas which i can try instead

            Taz742T Offline
            Taz742T Offline
            Taz742
            wrote on last edited by
            #5

            @TryToQT
            try startdetached

            QProcess *proces = new QProcess();
            proces->startDetached("C:/WINDOWS/system32/cmd.exe", QStringList << arg1 << arg2);

            Do what you want.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              aroow7777
              wrote on last edited by
              #6

              replace exec.start("cmd.exe", arguments); with
              exec.execute("cmd.exe", arguments);

              1 Reply Last reply
              0

              • Login

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