QT - create CMD and execute .bat file



  • 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();


  • Moderators

    @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);
    


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



  • 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.



  • @TryToQT
    try startdetached

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.