-------- Original-Nachricht --------
> Datum: Mon, 11 May 2009 19:44:55 +0200
> Von: Kornel Benko <kor...@lyx.org>
> An: lyx-devel@lists.lyx.org
> Betreff: QProcess

> I still think, it are the quotes, which are _not_ handled in QProcess.
> 
> 1.) Compile lyx with QProcess enabled.
> 2.) Strace -o xx.qprocess -f lyx.
>       open file
>       export as e.g. pdf
>       exit lyx
> 3.) egrep tex2pdf xx.qprocess| egrep execve
>       ==>
>               16424 execve("/usr2/kornel/bin/tex2pdf", ["tex2pdf", 
> "--overwrite", 
> "\'InstallDtree.tex\'", ">", "/dev/null"], [/* 73 vars */] <unfinished
> ...>
> ###############
> 
> Now the same without QProcess.
>  egrep tex2pdf xx.system| egrep execve
>       ==>
>               19091 execve("/bin/sh", ["sh", "-c", "tex2pdf  --overwrite  
> \'InstallDt"...], [/* 73 vars */]) = 0
>               19092 execve("/usr2/kornel/bin/tex2pdf", ["tex2pdf", 
> "--overwrite", 
> "InstallDtree.tex"], [/* 73 vars */]) = 0
> 
> #############
> I would say, here the "sh" is interpreting arguments and removing quotes.
> 
> Interesting is the description of
>       void QProcess::setArguments ( const QStringList & args ) [virtual]
> ...
> QProcess does not perform argument substitutions; for example, if you
> specify 
> "*" or "$DISPLAY", these values are passed to the process literally. If
> you 
> want to have the same behavior as the shell provides, you must do the 
> substitutions yourself; i.e. instead of specifying a "*" you must specify
> the 
> list of all the filenames in the current directory, and instead of
> "$DISPLAY" 
> you must specify the value of the environment variable DISPLAY. 
> ...
> 
> As I see it, we have to parse the string what.c_str(), isolate each
> parameter 
> and add this parameter via QProcess::addArgument().
> 
>       Kornel

I 've patched Qt on Linux to show the parameters used by QProcess,
and  they are the same as for system:

system() argument:
python -tt '/home/synth/sandbox/lyx/trunk/lib/configure.py'


QProcess passed arguments:
arg[ 0 ] =  python
arg[ 1 ] =  -tt
arg[ 2 ] =  '/home/synth/sandbox/lyx/trunk/lib/configure.py'


QProcess calling ::execvp
python: can't open file ''/home/synth/sandbox/lyx/trunk/lib/configure.py'': 
[Errno 2] No such file or directory



But QProcess doesn't use system, it uses execvp, and this is the problem:

"system() executes a command specified in string by calling /bin/sh -c string, 
...", means we rely on some bash functionality, but "The execv and execvp 
functions provide an array of pointers to null-terminated strings that 
represent the argument list available to the new program.", means it
provides the argv[] parameters for the called main().

http://linux.about.com/library/cmd/blcmdl3_execvp.htm


All the quotes we use are for the bash to handle multiple argument correctly. 
Not using the bash to start a new process and we having full
control over the arguments passed to the main function of the new
process. Thus, if I remove ' from the argument passed to pythons main,
cmd = cmd.replace("'", "");
phython executes the script and does not search for a script which resides in a 
filesystem where with a root path starts with '.



As Kornels trace show, the arguments are the same but when passed
to ::system, system calls sh which removes the quotes until they are
in the main function of the called process.

This is the problem with the quotes. which could be solved by 
1. isolate each argument
2. and remove the any quote (at least on Linux)


A other question is if we use variable expansion in our system calls.
When using QProcess we have to expand the variables before passing
them to QProcess. But here we could also think about a request to change
QProcess.

Peter













-- 
Neu: GMX FreeDSL Komplettanschluss mit DSL 6.000 Flatrate + Telefonanschluss 
für nur 17,95 Euro/mtl.!* 
http://dslspecial.gmx.de/freedsl-surfflat/?ac=OM.AD.PD003K11308T4569a

Reply via email to