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. Beginner start cmd.exe wit QProcess
Forum Updated to NodeBB v4.3 + New Features

Beginner start cmd.exe wit QProcess

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 3.3k 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.
  • C Offline
    C Offline
    chris0086
    wrote on last edited by
    #1

    Hi all,
    I have a Problem to start the CMD.EXE if I klick a button.
    @
    void MainWindow::openCMD()
    {
    QObject *parent;
    ui->spinBox->setValue(54);
    QString program = "cmd.exe";
    QStringList arguments = QStringList();

    arguments<<"cmd.exe -boardname=ST-LINK -Port=USB -Device=STM32F401xE -ProgMode=SWD -FilePorg=Nucleo.hex";
    

    // QTextStream cmd_output(p);
    //p->setArguments(arguments);

    QProcess *p = new QProcess(this);
    p->startDetached(program);
    @

    if i compile the projectand click on the button, the nothing happens.
    IfI write Startdetached, then the console starts but I how can I then make Inputs to the console?

    The dokumentation for QProcess dont helped me so far.

    EDIT:
    Now iam open the CMD with
    @QString program = "STVP_CmdLine.exe -Device=STM32F401xE -ProgMode=SWD -FileProg=nucleo.hex";
    QProcess *p = new QProcess(this);
    p->startDetached(program);@

    This works but i have a bigproblem:
    When Iclick on my button the console open and the rogramm Show the error that it can not find the file nucleo.hex

    But if i start the programm manual in the same Directory then everything works.
    Have anyone an idea what it could be?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      welcome to devnet

      At the moment you are starting only "cmd.exe".
      You are using startDetached which is static and does not require the allocation of an object. Typically it is easier IMHO to get "start" running first and simply switch to startDetached.

      You are setting up a string list with arguments, but the application "cmd.exe" is not an argument in that sense. You are pushing only one string to the string list instead of several as it is done typically.

      @
      void MainWindow::openCMD()
      {
      QObject *parent;
      ui->spinBox->setValue(54);
      QString program = "cmd.exe";
      QStringList arguments = QStringList();

      arguments<< "-boardname=ST-LINK";
      arguments<< "-Port=USB";
      arguments<< "-Device=STM32F401xE";
      arguments<< "-ProgMode=SWD";
      arguments<< "-FilePorg=Nucleo.hex";
      

      // QTextStream cmd_output(p);
      //p->setArguments(arguments);

      #ifdef 1
      QProcess *p = new QProcess(this);
      p->start(program, arguments);
      #else
      WProcess:startDetached( program, arguments );
      #endif
      @

      Check this out. Note: not tested; brain to keyboard only.

      Furthermore, check your syntax of the command it does not look correct.
      Finally

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        [quote author="chris0086" date="1397121092"]But if i start the programm manual in the same Directory then everything works.
        Have anyone an idea what it could be?[/quote]

        Most probably the working directory is different. Please set it using that override: "link":http://qt-project.org/doc/qt-5/qprocess.html#startDetached.

        (Z(:^

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chris0086
          wrote on last edited by
          #4

          i will test it.

          EDT:::
          So I added the following:
          @p->setWorkingDirectory("/");@
          before start.
          It seems to be working now but in the external Routine I haveto press Space after programing but as Long as the external Programm is running i dont get any Output in my plaintextEdit, so i have to push the sace button when i tink the Programm is finish. (UI freezes)
          How can i get the plaintextedit Show the actual Output of the programm?
          If i comment the setworkingdrectory out, then i get the whole Output from the Programm but i get the old failure.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MarianMMX
            wrote on last edited by
            #5

            p->setWorkingDirectory("/"); doesn't look good on Windows.

            @p->setWorkingDirectory(QCoreApplication::applicationDirPath());@

            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