elif mutlu elif mutlu - 26 days ago 10
C++ Question

List of variable contents with linux echo command Run with qtProcess

I want to do the "echo" command, which is used to show the variable content in the linux terminal, using the GUI.
I wrote this using qProcess, but it only printed $SHELL as output.

QString cmd = "echo $SHELL";
QProcess *process = new QProcess;
process->start(cmd);
process->waitForBytesWritten();
process->waitForFinished();
qDebug() << process->readAll();`


Qt code output:$SHELL
........................................

Terminal command:
[intern2atlas SETUP]$ echo $SHELL

output:/bin/tcsh

Answer

This is a example of code. Pls try with this:

   env.insert("TERM", "xterm");
    processo.setProcessEnvironment(env);

    //comando 1 - limpar a pasta
    comando = "echo";
    args.clear();
    args<<"$TERM";
    fullCommand = comando;
    for(int i = 0; i < args.count(); i++)
        fullCommand += " " + args.at(i);
    processo.start(comando,args,QIODevice::ReadOnly);
    processo.waitForFinished();
    stdOut = processo.readAllStandardOutput();
    stdError = processo.readAllStandardError();
    ui->commandTextEdit->append(fullCommand);
    ui->stdOutTextEdit->append(stdOut);
    ui->stdErrorTextEdit->append(stdError);

Refer: http://www.qtcentre.org/threads/58131-Execute-system-command-from-QProcess

Comments