1

I'm not really good at Qt and have no much knowledge in Ubuntu, but here is what I do: I launch gnome-terminal and then I start my *.sh file from it. How to do it from Qt? I've made:

QProcess *proc = new QProcess;
proc->start("gnome-terminal");
proc->write("build.sh\n");

But just terminal is opening and nothing happens, I can mannualy input command, but I need to do it from QProcess.

Mat
  • 202,337
  • 40
  • 393
  • 406
  • See [this](http://stackoverflow.com/questions/9086771/how-to-start-a-shell-script-with-qprocess) question – dvvrd Aug 15 '12 at 08:01
  • Two things: 1) gnome-terminal isn't started yet yet when start() returns. You have to connect to the started() signal of proc or call waitForStarted(). 2) write() write's to the terminal's stdin. That probably wont do what you want. (If it does, "echo build.sh | gnome-terminal" on a console would work as well). – Frank Osterfeld Aug 15 '12 at 17:03
  • @Frank Osterfeld Thanks for help, it didn`t work as I wanted. But I did it with "xterm" instead "gnome-terminal" and it worked fine. But only problem is - console window closes after *sh is finished, how to prevent it? QStringList args; args<<"/mnt/hgfs/Share/android-cts-2.3_r12/tools/StartGB.sh"; proc->start("xterm",args); proc->waitForStarted(30000) – user1600019 Aug 16 '12 at 07:20
  • Don't know, that'd be xterm-specific. – Frank Osterfeld Aug 16 '12 at 11:15

2 Answers2

0

It was said that the program you run is buffered, so that only the program write enough output, then you can get them.

I am working on this right now, but till now have found nothing that helps.

Edit:

OK, it most likely that the Qprocess uses pipe beforehand, and the pipe has a 4K buffer, so the idea is skip this buffer.

If you run your program after stdbuf like:

stdbuf -i0 -o0 -e0 gnome-terminal

it may work

j0k
  • 22,600
  • 28
  • 79
  • 90
Ian.Zhang
  • 151
  • 1
  • 10
0

Gnome-terminal is terminal emulator , it doesn`t execute commands(if it is not internal commands).

you need:

QProcess *proc = new Process(); proc->start("sh"); proc->waitForStarted();

or other command-line interpreters (sh, bash, cmd.exe), and then you can write command to the CLI with write method.

And if you want to read output you need this:

QString tmp = mProcess->readAllStandardOutput();

LyndaOlexandr
  • 311
  • 2
  • 10