A perl issue when execute system call

Discussion in 'Perl Misc' started by jeanwelly, Jul 19, 2007.

  1. jeanwelly

    jeanwelly Guest

    Hi,
    I met with a hang issue when using perl in some Unix server, don't
    why? Could you help?

    print "start...\n";
    my $result = `which command`;
    print "Stop...\n"; # can not call to here.
    chomp($result);

    It looks really strange to me. Thanks!
    jeanwelly, Jul 19, 2007
    #1
    1. Advertising

  2. jeanwelly

    Mirco Wahab Guest

    jeanwelly wrote:
    > I met with a hang issue when using perl in some
    > Unix server, don't why? Could you help?
    >
    > print "start...\n";
    > my $result = `which command`;
    > print "Stop...\n"; # can not call to here.
    > chomp($result);


    What is "command"?

    What happens if you put the "command"
    into a shell?

    $~jeanwelly> command [enter]


    Regards

    M.
    Mirco Wahab, Jul 19, 2007
    #2
    1. Advertising

  3. jeanwelly

    Mirco Wahab Guest

    Sherm Pendley wrote:
    > Mirco Wahab <-halle.de> writes:
    >> jeanwelly wrote:
    >>> my $result = `which command`;
    >>> print "Stop...\n"; # can not call to here.
    >>> chomp($result);

    >> What is "command"?

    >
    > Not "what" - "which". It's a *nix command that crawls your PATH and reports
    > where it finds the first occurrence of "command".


    Of course, you are correct. I didn't
    really touch the problem here, sorry.

    Regards & thanks for corrections

    M.
    Mirco Wahab, Jul 20, 2007
    #3
  4. jeanwelly

    jeanwelly Guest

    Hi Everyone,
    Sorry for not presented my problem clearly, here is clarification.
    `which whois`; # it will hang.

    It is executed in SUN UNIX OS, and some seems fine, some no; if key
    the command in shell directly, it tell me "shell built in command" in
    the issued SUN server; while in another SUN server that without this
    hang issue, the shell tells me the correct directory.

    For how long that I waited for the response, the answer is whole
    night :(

    On 7 20 , 4 56 , Mirco Wahab <> wrote:
    > Sherm Pendley wrote:
    > > Mirco Wahab <-halle.de> writes:
    > >> jeanwelly wrote:
    > >>> my $result = `which command`;
    > >>> print "Stop...\n"; # can not call to here.
    > >>> chomp($result);
    > >> What is "command"?

    >
    > > Not "what" - "which". It's a *nix command that crawls your PATH and reports
    > > where it finds the first occurrence of "command".

    >
    > Of course, you are correct. I didn't
    > really touch the problem here, sorry.
    >
    > Regards & thanks for corrections
    >
    > M.
    jeanwelly, Jul 20, 2007
    #4
  5. jeanwelly

    jeanwelly Guest

    One more info: in perl script, `which who`; will not hang, but `which
    whois`;.

    Thanks!

    On 7 20 , 7 05 , jeanwelly <> wrote:
    > Hi Everyone,
    > Sorry for not presented my problem clearly, here is clarification.
    > `which whois`; # it will hang.
    >
    > It is executed in SUN UNIX OS, and some seems fine, some no; if key
    > the command in shell directly, it tell me "shell built in command" in
    > the issued SUN server; while in another SUN server that without this
    > hang issue, the shell tells me the correct directory.
    >
    > For how long that I waited for the response, the answer is whole
    > night :(
    >
    > On 7 20 , 4 56 , Mirco Wahab <> wrote:
    >
    >
    >
    > > Sherm Pendley wrote:
    > > > Mirco Wahab <-halle.de> writes:
    > > >> jeanwelly wrote:
    > > >>> my $result = `which command`;
    > > >>> print "Stop...\n"; # can not call to here.
    > > >>> chomp($result);
    > > >> What is "command"?

    >
    > > > Not "what" - "which". It's a *nix command that crawls your PATH and reports
    > > > where it finds the first occurrence of "command".

    >
    > > Of course, you are correct. I didn't
    > > really touch the problem here, sorry.

    >
    > > Regards & thanks for corrections

    >
    > > M.- -

    >
    > - -
    jeanwelly, Jul 20, 2007
    #5
  6. jeanwelly

    jeanwelly Guest

    Hi Glenn,
    Actually I was using `which upd` to got the full datapath of clearcase
    bin/upd command, when I debug, I found similar hang issue of `which
    whois`, due to different server setup, I can't rely on the PATH to
    tell where is the bin/upd.

    The interesting thing is in SUN server1 I have the issue, but no in
    SUN server2, and the two with same kernel version and perl verison.

    On 7 20 , 10 27 , Glenn Jackman <> wrote:
    > At 2007-07-20 07:05AM, "jeanwelly" wrote:
    >
    > > > >> jeanwelly wrote:
    > > > >>> my $result = `which command`;
    > > > >>> print "Stop...\n"; # can not call to here.
    > > > >>> chomp($result);

    >
    > > Sorry for not presented my problem clearly, here is clarification.
    > > `which whois`; # it will hang.

    >
    > > It is executed in SUN UNIX OS, and some seems fine, some no; if key
    > > the command in shell directly, it tell me "shell built in command" in
    > > the issued SUN server; while in another SUN server that without this
    > > hang issue, the shell tells me the correct directory.

    >
    > What shell do you use that has whois as a builtin command?
    >
    > Doesn't 'which' read your .cshrc to learn about aliases? Do you have
    > anything in .cshrc that might be interfering?
    >
    > Anyway, you shouldn't be relying on the PATH in a Perl program -- it's a
    > security issue. Either specify the full path /usr/bin/whois where you
    > need it, or set $ENV{PATH} yourself to something like '/usr/bin:/bin'.
    >
    > --
    > Glenn Jackman
    > "You can only be young once. But you can always be immature." -- Dave Barry
    jeanwelly, Jul 20, 2007
    #6
  7. jeanwelly

    jeanwelly Guest

    On Jul 20, 11:51 pm, jeanwelly <> wrote:
    > Hi Glenn,
    > Actually I was using `which upd` to got the full datapath of clearcase
    > bin/upd command, when I debug, I found similar hang issue of `which
    > whois`, due to different server setup, I can't rely on the PATH to
    > tell where is the bin/upd.
    >
    > The interesting thing is in SUN server1 I have the issue, but no in
    > SUN server2, and the two with same kernel version and perl verison.
    >
    > On 7 20 , 10 27 , Glenn Jackman <> wrote:
    >
    > > At 2007-07-20 07:05AM, "jeanwelly" wrote:

    >
    > > > > >> jeanwelly wrote:
    > > > > >>> my $result = `which command`;
    > > > > >>> print "Stop...\n"; # can not call to here.
    > > > > >>> chomp($result);

    >
    > > > Sorry for not presented my problem clearly, here is clarification.
    > > > `which whois`; # it will hang.

    >
    > > > It is executed in SUN UNIX OS, and some seems fine, some no; if key
    > > > the command in shell directly, it tell me "shell built in command" in
    > > > the issued SUN server; while in another SUN server that without this
    > > > hang issue, the shell tells me the correct directory.

    >
    > > What shell do you use that has whois as a builtin command?

    >
    > > Doesn't 'which' read your .cshrc to learn about aliases? Do you have
    > > anything in .cshrc that might be interfering?

    >
    > > Anyway, you shouldn't be relying on the PATH in a Perl program -- it's a
    > > security issue. Either specify the full path /usr/bin/whois where you
    > > need it, or set $ENV{PATH} yourself to something like '/usr/bin:/bin'.

    >
    > > --
    > > Glenn Jackman
    > > "You can only be young once. But you can always be immature." -- Dave Barry


    Anyone has any suggestions to check? I'm still in the trouble. :(
    One of my workmate can use his account in the server (I encountered
    with hang issue) with NO the hang issue. I sourced his .cshrc, but
    still does not work.
    jeanwelly, Jul 23, 2007
    #7
  8. jeanwelly

    Guest

    On Jul 23, 6:10 am, jeanwelly <> wrote:
    > On Jul 20, 11:51 pm, jeanwelly <> wrote:
    >
    >
    >
    > > Hi Glenn,
    > > Actually I was using `which upd` to got the full datapath of clearcase
    > > bin/upd command, when I debug, I found similar hang issue of `which
    > > whois`, due to different server setup, I can't rely on the PATH to
    > > tell where is the bin/upd.

    >
    > > The interesting thing is in SUN server1 I have the issue, but no in
    > > SUN server2, and the two with same kernel version and perl verison.

    >
    > > On 7 20 , 10 27 , Glenn Jackman <> wrote:

    >
    > > > At 2007-07-20 07:05AM, "jeanwelly" wrote:

    >
    > > > > > >> jeanwelly wrote:
    > > > > > >>> my $result = `which command`;
    > > > > > >>> print "Stop...\n"; # can not call to here.
    > > > > > >>> chomp($result);

    >
    > > > > Sorry for not presented my problem clearly, here is clarification.
    > > > > `which whois`; # it will hang.

    >
    > > > > It is executed in SUN UNIX OS, and some seems fine, some no; if key
    > > > > the command in shell directly, it tell me "shell built in command" in
    > > > > the issued SUN server; while in another SUN server that without this
    > > > > hang issue, the shell tells me the correct directory.

    >
    > > > What shell do you use that has whois as a builtin command?

    >
    > > > Doesn't 'which' read your .cshrc to learn about aliases? Do you have
    > > > anything in .cshrc that might be interfering?

    >
    > > > Anyway, you shouldn't be relying on the PATH in a Perl program -- it's a
    > > > security issue. Either specify the full path /usr/bin/whois where you
    > > > need it, or set $ENV{PATH} yourself to something like '/usr/bin:/bin'.

    >
    > > > --
    > > > Glenn Jackman
    > > > "You can only be young once. But you can always be immature." -- Dave Barry

    >
    > Anyone has any suggestions to check? I'm still in the trouble. :(
    > One of my workmate can use his account in the server (I encountered
    > with hang issue) with NO the hang issue. I sourced his .cshrc, but
    > still does not work.


    Rewrite your own version of which within perl:
    #!/usr/bin/env perl

    use strict;
    use warnings FATAL => 'all';

    unless(@ARGV){
    print "Too few arguments\n";
    exit;
    }

    foreach my $file(@ARGV){
    my $path = (grep {-e "$_/$file"} split(/:+/, $ENV{PATH}))[0];
    if($path){
    print "$path/$file\n";
    }else{
    print "$file: Command not found.\n";
    }
    }

    Running it gives me:
    l-xterm-7:~/sandbox/scratch> ./perlWhich.pl perl doggy fish gdb whois
    /home/utils/perl-5.8.8/bin//perl
    doggy: Command not found.
    fish: Command not found.
    /usr/bin/gdb
    /usr/bin/whois
    l-xterm-7:~/sandbox/scratch>
    , Aug 4, 2007
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lord0
    Replies:
    0
    Views:
    888
    lord0
    Apr 7, 2004
  2. Replies:
    3
    Views:
    354
    Keith Thompson
    Jun 22, 2005
  3. Savas Ates
    Replies:
    1
    Views:
    278
    Patrice
    Aug 17, 2004
  4. Petterson Mikael

    Execute another perl script from my perl script

    Petterson Mikael, Jan 5, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    139
    Paul Lalli
    Jan 5, 2005
  5. Replies:
    20
    Views:
    716
    Gunnar Hjalmarsson
    Jan 18, 2005
Loading...

Share This Page