Beginner start cmd.exe wit QProcess



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


  • Moderators

    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


  • Moderators

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



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



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

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


Log in to reply
 

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