using *.* to copy files using spawnl

Following function works well for source if it is a whole directory ,

pid = spawnl( P_NOWAIT, “/bin/cp”, “cp”, “-vcLR”, “/source”,
“/destination”, NULL );

However, it deosnt work if the /source is like /*.txt when u just want
to copy certain files using *.
Anyone got suggestion

ran zhang <rzhang@vamcointernational.com> wrote:

Following function works well for source if it is a whole directory ,

pid = spawnl( P_NOWAIT, “/bin/cp”, “cp”, “-vcLR”, “/source”,
“/destination”, NULL );

However, it deosnt work if the /source is like /*.txt when u just want
to copy certain files using *.

The problem is that it isn’t “cp” which expands the *.txt, it is the
shell.

Hm… you were asking about getting the pid from a system() call as
well, weren’t you? So, I can’t suggest going back to using system()
to do this.

Depends on how much code you want to write, and what your requirements
are.

Here are a sample of some of the issues to think about, but not possibly
all, before I can know the best answer:

Do you know the files in advance? (That is, you know it is alpha.txt,
beta.txt, gamma.txt and delta.txt; but you are thinking *.txt because
that is what you would type at the command line – or is there some
arbitrary set of files that can be dynamically created that you don’t
track in the code, and won’t know in advance.)

How important is effeciency? Is this going to be a frequent operation?
Is it a setup/backup type operation, or part of normal running?

How important is coding time?

Do you need to know when the operation is finished?

Do you need to do other things while the operation proceeds, or can you
just block on it until it is finished?

-David

QNX Training Services
dagibbs@qnx.com

Could you do something like

pid = spawnl( P_NOWAIT, “/bin/sh”, “-c”, “exec /bin/cp -v /source/*.txt /destination”, NULL );

David Gibbs <dagibbs@qnx.com> wrote:

ran zhang <> rzhang@vamcointernational.com> > wrote:
Following function works well for source if it is a whole directory ,

pid = spawnl( P_NOWAIT, “/bin/cp”, “cp”, “-vcLR”, “/source”,
“/destination”, NULL );

However, it deosnt work if the /source is like /*.txt when u just want
to copy certain files using *.

The problem is that it isn’t “cp” which expands the *.txt, it is the
shell.

Hm… you were asking about getting the pid from a system() call as
well, weren’t you? So, I can’t suggest going back to using system()
to do this.

Depends on how much code you want to write, and what your requirements
are.

Here are a sample of some of the issues to think about, but not possibly
all, before I can know the best answer:

Do you know the files in advance? (That is, you know it is alpha.txt,
beta.txt, gamma.txt and delta.txt; but you are thinking *.txt because
that is what you would type at the command line – or is there some
arbitrary set of files that can be dynamically created that you don’t
track in the code, and won’t know in advance.)

How important is effeciency? Is this going to be a frequent operation?
Is it a setup/backup type operation, or part of normal running?

How important is coding time?

Do you need to know when the operation is finished?

Do you need to do other things while the operation proceeds, or can you
just block on it until it is finished?

-David

QNX Training Services
dagibbs@qnx.com


cburgess@qnx.com

ran zhang wrote:

Following function works well for source if it is a whole directory ,

pid = spawnl( P_NOWAIT, “/bin/cp”, “cp”, “-vcLR”, “/source”,
“/destination”, NULL );

However, it deosnt work if the /source is like /*.txt when u just want
to copy certain files using *.
Anyone got suggestion

Did you think about the ‘-P’ option? Like:

pid = spawnl( P_NOWAIT, “/bin/cp”, “cp”, “-vcLR”,"-P","*.txt",
“/source”, “/destination”, NULL );


\


| / | __ ) | Karsten.Hoffmann@mbs-software.de MBS-GmbH
| |/| | _ _
\ Phone : +49-2151-7294-38 Karsten Hoffmann
| | | | |
) |__) | Fax : +49-2151-7294-50 Roemerstrasse 15
|| ||// Mobile: +49-172-3812373 D-47809 Krefeld