system und metachar

T

Tof

Hi from a newby,

I wanted to use system like: system("mv","*","targetDir);
But * ist not interpreted at all and the commande failed.
What would be the best way to do that ?

Greetings from Paris,

Christophe
 
S

Shawn Corey

Tof said:
Hi from a newby,

I wanted to use system like: system("mv","*","targetDir);
But * ist not interpreted at all and the commande failed.
What would be the best way to do that ?

Greetings from Paris,

Christophe

Bonjour,

Try: system( "mv * targetdir" );
 
T

Tad McClellan

I wanted to use system like: system("mv","*","targetDir);


This part of the description of the system() function will
be important here:

Note
that argument processing varies depending on the
number of arguments. If there is more than one
argument in LIST, or if LIST is an array with more
than one value, starts the program given by the
first element of the list with arguments given by
the rest of the list. If there is only one scalar
argument, the argument is checked for shell
metacharacters, and if there are any, the entire
argument is passed to the system's command shell
for parsing


So your call above will not invoke a shell.

But * ist not interpreted at all


Because it is the shell that interprets it, and there is no shell.

and the commande failed.
What would be the best way to do that ?


Either expand it yourself:

!system('mv', glob('*'), 'targetDir') or die "mv failed $!";
#or
!system('mv', <*>, 'targetDir') or die "mv failed $!";


Or call system such that it _will_ invoke a shell (and accept
all of the dangers that go with it):

!system('mv * targetDir') or die "mv failed $!";
 
C

Chris Mattern

Tof said:
Hi from a newby,

I wanted to use system like: system("mv","*","targetDir);
But * ist not interpreted at all and the commande failed.
What would be the best way to do that ?
When you hand system multiple strings, it directly invokes
the first string as the program name, passing it the other
strings as parameters. The shell is never invoked, so none
of the shell metacharacters get interpreted. In order to
get system to invoke the shell to parse your command line,
you need to pass it only *one* string, like so:

system("mv * targetDir");

Chris Mattern
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top