A perl issue when execute system call

J

jeanwelly

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!
 
M

Mirco Wahab

jeanwelly said:
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.
 
M

Mirco Wahab

Sherm said:
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.
 
J

jeanwelly

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 :(
 
J

jeanwelly

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

Thanks!
 
J

jeanwelly

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.
 
J

jeanwelly

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.

At 2007-07-20 07:05AM, "jeanwelly" wrote:
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'.

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.
 
J

Joseph.Trapasso

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>
 

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,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top