Re: System call not acting as expected
From: Mike Kohary (sorry_at_no.spam)
Date: 09/08/04
- Next message: Alan J. Flavell: "Re: Replacing Ampertsand in cgi url"
- Previous message: Eric Schwartz: "Re: System call not acting as expected"
- In reply to: Eric Schwartz: "Re: System call not acting as expected"
- Next in thread: John W. Krahn: "Re: System call not acting as expected"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 8 Sep 2004 12:17:49 -0700
"Eric Schwartz" <emschwar@pobox.com> wrote in message
news:etobrggpoux.fsf@wilson.emschwar...
>
> Please read:
>
> perldoc -f system
>
> In general, if a function isn't doing what you expect, you should read
> the documentation for it first via 'perldoc -f $function', before
> posting here.
Thanks, I was unaware of that. Newbie alert! :)
> If you had, you would have read (in the first
> paragraph, no less!):
>
> 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 (this is "/bin/sh
> -c" on Unix platforms, but varies on other platforms).
>
> You seem to be expecting the latter behaviour, but because you're
> using commas, you're creating a list with more than one value, and
> thus trying getting the former. Why are you using commas there
> anyhow? Why not use the string concatenation operator:
>
> system("ls -d ".$log_location."*_instance_".$instance." > logfile_dirs");
>
> or just interpolate directly into the command line (this is the most
> perlish solution that uses system):
>
> system("ls -d $log_location*_instance_$instance > logfile_dirs");
>
> or better yet
>
> my @logfile_dirs = `ls -d $log_location*_instance_$instance`;
>
> Of course, this last only works if the next step is to read the file
> logfile_dirs into an array, which seems likely, but I don't know your
> application.
That's exactly right, and thanks for all the suggested alternatives - they
work perfectly of course. :)
> > The idea is to ls -d some directories to the file logfile_dirs.
>
> You might also look into opendir/readdir to iterate through
> directories; that is generally more portable, and will save you from
> other possible sillinesses, like when someone aliases 'ls' to 'ls
> --color', exports the alias, and then runs your program. Then you get
> all sorts of fun problems, like having to sort out terminal escape
> sequences.
Good idea - I didn't think of that either. I have so much to learn. Thanks
for all the help!
Mike
- Next message: Alan J. Flavell: "Re: Replacing Ampertsand in cgi url"
- Previous message: Eric Schwartz: "Re: System call not acting as expected"
- In reply to: Eric Schwartz: "Re: System call not acting as expected"
- Next in thread: John W. Krahn: "Re: System call not acting as expected"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|