0

I am currently making a GUI using QT4.8 which basically needs to launch a console application. However, because this console application tries to fetch some environment variables, I can't seem to manage to make this work. I am using QProcess obviously and have tried several solutions :

process->start("./yarpbridge", QStringList() << "--from" << "tmp.ini");

This solution does not spawn a console window and besides, by redirecting the output to qDebug(), it prints the erros corresponding to the lack of environment variables.

process->start("gnome-terminal", QStringList() << "-e" << "zsh" << "-c" << "\"./yarpbridge --from tmp.ini"\");

This solution does launch a console window but it nevertheless displays the error messages because somehow .zshrc was probably not consulted when opening the console window.

Would you have a solution that would allow me to do this, and even better that would not only work with "gnome-terminal" and "zsh" users ?

Thanks a lot,

wrousseau
  • 311
  • 3
  • 12

1 Answers1

0

Can you post the error you are getting?

It is very strange because you don't need to start a terminal in order to run a CLI program, maybe after posting your error message I might get an idea what the problem is.

Also you can try this as well:

#include <stdio.h>

char buffer[1024];
FILE* fd = popen("/path/to/yarpbridge", "r");

if (fd == NULL) {
    // Error: do something
}

while(NULL != fgets(buffer, sizeof(buffer), fd)) {
    QString s(buffer);
    s = s.stripWhiteSpace();
    // s contains the output, pretty much as readAllStandardOutput() in QProcess
}

// don't forget to close file.
close (fd);
milot
  • 1,060
  • 2
  • 8
  • 17
  • I'd rather not use the C standard... The error output was pretty much relevant to my program when the environment variable is not defined. However, I think I've figured it out by running a shell in interactive mode (-i flag). – wrousseau May 31 '13 at 15:04