[PyQt] QProcess arguments list problem

Ingmar Steen iksteen at gmail.com
Wed Nov 21 20:01:19 GMT 2007


On Nov 21, 2007 7:53 PM, kib2 <kib2 at free.fr> wrote:
> Hi,
>
> I'm using QProcess to launch some commands, no problem with basic ones,
> ie to launch a LaTeX file with pdflatex I use:
>
> self.proc.start("pdflatex", QtCore.QStringList(["my_file.tex"]))
>
> Now, I wanted to launch the following command :
>
> "lout my_file.lout > my_file.ps"
>
> I've made these tries but they all failed :
>
> 1. self.proc.start("lout",
> QtCore.QStringList(["my_file.lout",">","my_file.ps"]))
>
> 2. self.proc.start("lout", QtCore.QStringList(["my_file.lout"," >
> ","my_file.ps"]))
>
> Any idea ?
> Thanks a lot in advance.
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>

Hi,

That won't work because the '>' (redirect) you use in a shell
environment doesn't 'magically' work. The shell (bash, ksh, etc)
performs the job of capturing the child process' 'stdout' (the regular
output of the process) and redirects it to a file.

To achieve that you can do two things:
1) The proper way: Use the fact that QProcess allows you to read the
child process' stdout and write it to a file yourself.

>From the documentation:

QProcess allows you to treat a process as a sequential I/O device. You
can write to and read from the process just as you would access a
network connection using QTcpSocket. You can then write to the
process's standard input by calling write(), and read the standard
output by calling read(), readLine(), and getChar(). Because it
inherits QIODevice, QProcess can also be used as an input source for
QXmlReader, or for generating data to be uploaded using QFtp.

2) The dirty way: Use a shell to do this for you (and lose
cross-platform compatibility as an added bonus!)
Instead of spawning your process, spawn a shell:
command = 'sh'
args = ['-c', 'lout myfile.lout > myfile.ps']

I really do suggest you take option 1.

Ingmar


More information about the PyQt mailing list