Help for KProcess

W. Tasin tasin at e-technik.fh-muenchen.de
Thu Jan 13 17:34:49 GMT 2000


Peter.J.Robinson at icl.com wrote:
> 
> Try:
> 
> proc << "cp " << source << destination;
> 
> 
> PJR
> 
> -----Original Message-----
> From: Jean-Paul Miniscloux [mailto:jpminiscloux at nordnet.fr]
> Sent: 29 December 1999 18:15
> To: kdevelop at barney.cs.uni-potsdam.de
> Subject: Help for KProcess
> 
> Hello,
> 
> I have a problem with KProcess.
> Here this that I would want to make:
> I have a directory containing a MySQL database who serves me of pattern
> (/usr/mysql/modele).
> I create a new database who is going to serve me for my software (for
> example /usr/mysql/THOMAS).
> I must copy the whole some tables of the database "modele" toward the
> database "THOMAS"
> I use the for it orders: cp  /usr/mysql/modele/*  /usr/mysql/THOMAS
> 
> After numerous tests with KProcess I don't have any result. Here the used
> code.
>  Someone would can he say me this who doesn't go.
> 
> Thank you.
> 
> source = "/var/mysql/modele/*";
> 
> destination = "/var/mysql/" + base + QString("/");
> 
> KShellProcess proc;
> 
> proc.clearArguments();
> 
> proc << "cp " + (QString) "'" + source + (QString) "' '" + destination +
> (QString) "'";
> 
> proc.start(KProcess::Block,KProcess::AllOutput); */


Hi all,

here some statements to clear the situation (at least I hope so):

The problem you are talking about isn't a problem of KShellProcess it is
a problem of the shell subtitution of the asterisk:

If you are making:
cp '/var/mysql/modele/*' '/var/mysql/foo/'

so only ONE file with the name '*' (yes - it's allowed!!) will be copied
into /var/msql/foo
---> which results: not the desired copy process



If you will use
proc << "cp " + source + " " + destination;  
or
proc << "cp" << source << destination;
or 
proc << "sh" << "-c" << "cp" << source << destination; (this for
KProcess)

you would have the desired result, BUT this will work only if the source
(or destination) path hasn't any special shell character in it.
for example: if you want to copy files from the path /var/*mysql*/modele 
the solution above 

> proc << "cp " + (QString) "'" + source + (QString) "' '" + destination +
> (QString) "'";

always works if you have to copy ONE file.

If you want to copy multiple files from a "special" directory you have
to use the following:

cp '/var/*mysql*/'* '/var/mysql/foo'

(so the last asterisk will be shell substituted)

So IMHO the "perfect" solution would be in this case:

> source = "/var/mysql/modele";
> 
> destination = "/var/mysql/" + base;
> 
> KShellProcess proc;
> 
> proc.clearArguments();
> 
now some versions:
> proc << QString("cp '") +source+ "/'* '"+destination + "'";
or
> proc << "cp" << QString("'")+source+ "/'*" << QString("'")+ destination + "'";

> 
> proc.start(KProcess::Block,KProcess::AllOutput); 

so the variables "source" and "destination" now can contain any type of
pathname.

Have fun with these examples...

Ciao

Walter
--
oohhh sveglia.... il mondo e' ammalato, ma x colpa di chi.........
(Zucchero)
:-------W. Tasin, FB 04,
FHM-------------------PGP-KeyID:0x7961A645----------:
<Key-Fingerprint: 1610 835F 0080 32F4 6140  6CF7 A7D0 44CD 7961A645>
<http://wwwkeys.pgp.net:11371/pks/lookup?op=index&search=0x7961A645&fingerprint=on>




More information about the KDevelop mailing list