Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > system call - how-to.

Reply
Thread Tools

system call - how-to.

 
 
elsiddik
Guest
Posts: n/a
 
      05-01-2007
well i wanted to just mess a little with perl and try if it can give
me the same result of a small shell script i wrote a little while ago
but it doesnt seems to work out with me . here is my shell script

#!/bin/bash
DIRECTORY="/usr/bin"
for file in $DIRECTORY/*
do whatis `basename $file`

done
exit 0

i tried to run a similiar perl code by typing on command line.

perl -e "system qw (whatis /usr/bin/*)"

but its not giving me the same whatislog - what am i doing wrong ?

cheers.


zaher el siddik

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      05-01-2007
On May 1, 7:22 am, elsiddik <(E-Mail Removed)> wrote:
> well i wanted to just mess a little with perl and try if it can give
> me the same result of a small shell script i wrote a little while ago
> but it doesnt seems to work out with me . here is my shell script
>
> #!/bin/bash
> DIRECTORY="/usr/bin"
> for file in $DIRECTORY/*
> do whatis `basename $file`
>
> done
> exit 0
>
> i tried to run a similiar perl code by typing on command line.
>
> perl -e "system qw (whatis /usr/bin/*)"
>
> but its not giving me the same whatislog - what am i doing wrong ?


You are using the qw operator. This operator takes a space-separated
list of barewords and returns a quoted list of words. That is, your
system() call is equivalent to:
system('whatis', '/usr/bin/*');

When you call system() with two or more arguments, Perl executes the
first argument directly, passing in the remaining arguments. It does
not spawn a shell at all. So the * in the second argument there is
not interpreted by any shell to mean "all files", because there is no
shell to do the interpreting. So you are litterally calling "whatis"
on the single argument "/usr/bin/*". Since no such file with that
name exists, there is no output.

Change your qw() to qq() or q(), and read up on `perldoc -f system`
for more information.

Paul Lalli

 
Reply With Quote
 
 
 
 
elsiddik
Guest
Posts: n/a
 
      05-01-2007
On May 1, 10:45 pm, Paul Lalli <(E-Mail Removed)> wrote:
> On May 1, 7:22 am, elsiddik <(E-Mail Removed)> wrote:
>
>
>
> > well i wanted to just mess a little with perl and try if it can give
> > me the same result of a small shell script i wrote a little while ago
> > but it doesnt seems to work out with me . here is my shell script

>
> > #!/bin/bash
> > DIRECTORY="/usr/bin"
> > for file in $DIRECTORY/*
> > do whatis `basename $file`

>
> > done
> > exit 0

>
> > i tried to run a similiar perl code by typing on command line.

>
> > perl -e "system qw (whatis /usr/bin/*)"

>
> > but its not giving me the same whatislog - what am i doing wrong ?

>
> You are using the qw operator. This operator takes a space-separated
> list of barewords and returns a quoted list of words. That is, your
> system() call is equivalent to:
> system('whatis', '/usr/bin/*');
>
> When you call system() with two or more arguments, Perl executes the
> first argument directly, passing in the remaining arguments. It does
> not spawn a shell at all. So the * in the second argument there is
> not interpreted by any shell to mean "all files", because there is no
> shell to do the interpreting. So you are litterally calling "whatis"
> on the single argument "/usr/bin/*". Since no such file with that
> name exists, there is no output.
>
> Change your qw() to qq() or q(), and read up on `perldoc -f system`
> for more information.
>
> Paul Lalli



On May 1, 10:45 pm, Paul Lalli <(E-Mail Removed)> wrote:
> On May 1, 7:22 am, elsiddik <(E-Mail Removed)> wrote:
>
>
>
> > well i wanted to just mess a little with perl and try if it can give
> > me the same result of a small shell script i wrote a little while ago
> > but it doesnt seems to work out with me . here is my shell script

>
> > #!/bin/bash
> > DIRECTORY="/usr/bin"
> > for file in $DIRECTORY/*
> > do whatis `basename $file`

>
> > done
> > exit 0

>
> > i tried to run a similiar perl code by typing on command line.

>
> > perl -e "system qw (whatis /usr/bin/*)"

>
> > but its not giving me the same whatislog - what am i doing wrong ?

>
> You are using the qw operator. This operator takes a space-separated
> list of barewords and returns a quoted list of words. That is, your
> system() call is equivalent to:
> system('whatis', '/usr/bin/*');
>
> When you call system() with two or more arguments, Perl executes the
> first argument directly, passing in the remaining arguments. It does
> not spawn a shell at all. So the * in the second argument there is
> not interpreted by any shell to mean "all files", because there is no
> shell to do the interpreting. So you are litterally calling "whatis"
> on the single argument "/usr/bin/*". Since no such file with that
> name exists, there is no output.
>
> Change your qw() to qq() or q(), and read up on `perldoc -f system`
> for more information.
>
> Paul Lalli


well i tried running the code with q and qq but im still getting the
same output --
the part that i cant understand is when you run the shell script - i
could see all the /usr/bin/files output with <whatis> details ,
with perls everything looks quiet good also but instead of the
<whatis> details - keeps giving me /usr/bin/filename: nothing
appropriate.

here is an outlook:

animate (1) - animates an image or image sequence on any
X server << shell script
animate: nothing appropriate.

i even tried to write a perl script - used File::Basename

<code>

#!/usr/bin/perl -w

use strict;
use warnings;

use File::Basename;

my $path = "/usr/bin/";
my $files = basename($path);
my $dir = dirname($path);

print "dir is $dir , files is $files\n";

system "whatis $path";

</code>

im keep having the same log

its confusing me big time.

cheers,

zaher el siddik
http://elsiddik.blogspot.com/

 
Reply With Quote
 
Klaus
Guest
Posts: n/a
 
      05-01-2007
> > On May 1, 7:22 am, elsiddik <(E-Mail Removed)> wrote:
> > > perl -e "system qw (whatis /usr/bin/*)"
> > > but its not giving me the same whatislog - what am i doing wrong ?


> On May 1, 10:45 pm, Paul Lalli <(E-Mail Removed)> wrote:
> > You are using the qw operator.
> > Change your qw() to qq() or q()


On May 1, 3:11 pm, elsiddik <(E-Mail Removed)> wrote:
> well i tried running the code with q and qq
> my $path = "/usr/bin/";
> system "whatis $path";
> its confusing me big time.


It's confusing you, probably because you forgot to put an asterisk at
the end of /usr/bin/

--
Klaus

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      05-01-2007
> > On May 1, 7:22 am, elsiddik <(E-Mail Removed)> wrote:
>
> > > perl -e "system qw (whatis /usr/bin/*)"

>
> > > but its not giving me the same whatislog - what am i doing wrong ?

>
> > You are using the qw operator. This operator takes a space-separated
> > list of barewords and returns a quoted list of words. That is, your
> > system() call is equivalent to:
> > system('whatis', '/usr/bin/*');

>
> > Change your qw() to qq() or q(), and read up on `perldoc -f system`
> > for more information.


> well i tried running the code with q and qq but im still getting the
> same output --


I don't believe you. Please post a short-but-complete script that
demonstrates this, like so:

$ perl -e'system qq(whatis /usr/bin/*)'
acctcom acctcom (1) - search and print process accounting
files
activation-client activation-client () - bonobo-
activationdebugging tool
adb adb (1) - general-purpose debugger
<remainder snipped>

> the part that i cant understand is when you run the shell script - i
> could see all the /usr/bin/files output with <whatis> details ,
> with perls everything looks quiet good also but instead of the
> <whatis> details - keeps giving me /usr/bin/filename: nothing
> appropriate.


Again, post a short-but-complete script that generates this output.

> i even tried to write a perl script - used File::Basename


I have no idea what you think File::Basename has to do with this.

> <code>
>
> #!/usr/bin/perl -w
>
> use strict;
> use warnings;
>
> use File::Basename;
>
> my $path = "/usr/bin/";
> my $files = basename($path);
> my $dir = dirname($path);


I still have no idea what you think File::Basename has to do with
this.

> print "dir is $dir , files is $files\n";


Didn't that output tell you you're doing something very wrong? It
should have claimed that $dir is /usr and $files is the empty string.

> system "whatis $path";


Now you're just calling whatis on "/usr/bin/", rather than on all the
files in /usr/bin. Why did you omit the * this time?

Paul Lalli

 
Reply With Quote
 
elsiddik
Guest
Posts: n/a
 
      05-01-2007
On May 2, 3:12 am, Paul Lalli <(E-Mail Removed)> wrote:
> > > On May 1, 7:22 am, elsiddik <(E-Mail Removed)> wrote:

>
> > > > perl -e "system qw (whatis /usr/bin/*)"

>
> > > > but its not giving me the same whatislog - what am i doing wrong ?

>
> > > You are using the qw operator. This operator takes a space-separated
> > > list of barewords and returns a quoted list of words. That is, your
> > > system() call is equivalent to:
> > > system('whatis', '/usr/bin/*');

>
> > > Change your qw() to qq() or q(), and read up on `perldoc -f system`
> > > for more information.

> > well i tried running the code with q and qq but im still getting the
> > same output --

>
> I don't believe you. Please post a short-but-complete script that
> demonstrates this, like so:
>
> $ perl -e'system qq(whatis /usr/bin/*)'
> acctcom acctcom (1) - search and print process accounting
> files
> activation-client activation-client () - bonobo-
> activationdebugging tool
> adb adb (1) - general-purpose debugger
> <remainder snipped>
>
> > the part that i cant understand is when you run the shell script - i
> > could see all the /usr/bin/files output with <whatis> details ,
> > with perls everything looks quiet good also but instead of the
> > <whatis> details - keeps giving me /usr/bin/filename: nothing
> > appropriate.

>
> Again, post a short-but-complete script that generates this output.
>
> > i even tried to write a perl script - used File::Basename

>
> I have no idea what you think File::Basename has to do with this.
>
> > <code>

>
> > #!/usr/bin/perl -w

>
> > use strict;
> > use warnings;

>
> > use File::Basename;

>
> > my $path = "/usr/bin/";
> > my $files = basename($path);
> > my $dir = dirname($path);

>
> I still have no idea what you think File::Basename has to do with
> this.
>
> > print "dir is $dir , files is $files\n";

>
> Didn't that output tell you you're doing something very wrong? It
> should have claimed that $dir is /usr and $files is the empty string.
>
> > system "whatis $path";

>
> Now you're just calling whatis on "/usr/bin/", rather than on all the
> files in /usr/bin. Why did you omit the * this time?
>
> Paul Lalli



i could solve it with :
perl -e 'chdir (shift || "/usr/bin"); system whatis => <*>'

thx anyway guys

zaher elsiddik
http;//elsiddik.blogspot.com/

 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      05-06-2007
On 2007-05-01 11:22, elsiddik <(E-Mail Removed)> wrote:
> well i wanted to just mess a little with perl and try if it can give
> me the same result of a small shell script i wrote a little while ago
> but it doesnt seems to work out with me . here is my shell script
>
> #!/bin/bash
> DIRECTORY="/usr/bin"
> for file in $DIRECTORY/*
> do whatis `basename $file`
>
> done
> exit 0
>
> i tried to run a similiar perl code by typing on command line.
>
> perl -e "system qw (whatis /usr/bin/*)"
>
> but its not giving me the same whatislog - what am i doing wrong ?


Your perl script doesn't do the same thing as your shell script.

Your shell script loops over all the filenames matching /usr/bin/*,
extracting the basename of each and calling whatis with that. So if your
/usr/bin/* starts like this:

/usr/bin/822-date
/usr/bin/Mail
/usr/bin/X
/usr/bin/X11
/usr/bin/Xorg
/usr/bin/[
/usr/bin/a2p
/usr/bin/aconnect
/usr/bin/acpi
/usr/bin/acpi_fakekey

it will invoke

whatis 822-date
whatis Mail
whatis X
...

Your perl script just invokes the shell with the command
"whatis /usr/bin/*" (assuming qq instead of qw), which will will in turn
invoke

whatis /usr/bin/822-date /usr/bin/Mail /usr/bin/X /usr/bin/X11 ...


hp


--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | http://www.velocityreviews.com/forums/(E-Mail Removed) |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Help replacing os.system call with subprocess call David Pratt Python 0 04-07-2008 01:38 PM
Help replacing os.system call with subprocess call David Pratt Python 0 04-07-2008 05:32 AM
System call and library call leoman730 C++ 6 05-06-2007 12:37 AM
system call and library call rahul8143@gmail.com C Programming 7 08-23-2005 01:24 PM
System.Security.SecurityException: Error de solicitud de permiso de tipo System.Net.WebPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. Luis Esteban Valencia ASP .Net 0 07-14-2005 01:43 PM



Advertisments