[Qt-interest] qprocess cannot run unix commands?

Thiago Macieira thiago at kde.org
Mon Jun 7 13:14:30 CEST 2010


Em Segunda-feira 07 Junho 2010, às 12:53:18, Gabriele Kahlout escreveu:
> Hello, I was wondering why this result is empty in:
> 
>   QProcess gzip;
> 
>     gzip.start("bash");
> 
>     assert(gzip.waitForStarted());
> 
>    gzip.write("ls");
> 
>    gzip.closeWriteChannel();
> 
>    QByteArray result = gzip.readAll();
> 
>    cout << result.data() ;
> 
>    gzip.close();

The problem is not QProcess. You need to read bash documentation.

From the INVOCATION part of the manual:
       An  interactive  shell  is one started without non-option arguments and
       without the -c option whose standard input and error are both connected
       to  terminals  (as determined by isatty(3)), or one started with the -i
       option.  PS1 is set and $- includes i if bash is interactive,  allowing
       a shell script or a startup file to test this state.

You started it without any non-option arguments, without -c, but you didn't 
connect to a terminal. You connected them to a pipe, by way of QProcess.

> is this true:
> http://www.linuxquestions.org/questions/programming-9/problems-running-cons
> ole-commands-using-qprocess-672207/

No. QProcess can run any command that exists as an external binary.

To run shell built-ins, you need to ask the shell to run them for you (see the 
-c option to bash).

> The documentation illuded me that my code should work.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100607/dd976f47/attachment.bin 


More information about the Qt-interest-old mailing list