Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > A perl issue when execute system call

Reply
Thread Tools

A perl issue when execute system call

 
 
jeanwelly
Guest
Posts: n/a
 
      07-19-2007
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!

 
Reply With Quote
 
 
 
 
Mirco Wahab
Guest
Posts: n/a
 
      07-19-2007
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.
 
Reply With Quote
 
 
 
 
Mirco Wahab
Guest
Posts: n/a
 
      07-20-2007
Sherm Pendley wrote:
> Mirco Wahab <(E-Mail Removed)-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.

 
Reply With Quote
 
jeanwelly
Guest
Posts: n/a
 
      07-20-2007
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 <(E-Mail Removed)> wrote:
> Sherm Pendley wrote:
> > Mirco Wahab <(E-Mail Removed)-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.



 
Reply With Quote
 
jeanwelly
Guest
Posts: n/a
 
      07-20-2007
One more info: in perl script, `which who`; will not hang, but `which
whois`;.

Thanks!

On 7 20 , 7 05 , jeanwelly <(E-Mail Removed)> 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 <(E-Mail Removed)> wrote:
>
>
>
> > Sherm Pendley wrote:
> > > Mirco Wahab <(E-Mail Removed)-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.- -

>
> - -



 
Reply With Quote
 
jeanwelly
Guest
Posts: n/a
 
      07-20-2007
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 <(E-Mail Removed)> 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



 
Reply With Quote
 
jeanwelly
Guest
Posts: n/a
 
      07-23-2007
On Jul 20, 11:51 pm, jeanwelly <(E-Mail Removed)> 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 <(E-Mail Removed)> 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.



 
Reply With Quote
 
Joseph.Trapasso@gmail.com
Guest
Posts: n/a
 
      08-04-2007
On Jul 23, 6:10 am, jeanwelly <(E-Mail Removed)> wrote:
> On Jul 20, 11:51 pm, jeanwelly <(E-Mail Removed)> 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 <(E-Mail Removed)> 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>

 
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
system call and library call rahul8143@gmail.com C Programming 7 08-23-2005 01:24 PM
CGI: Execute a perl script inside another perl script xdarcos@hotmail.com Perl Misc 20 01-18-2005 12:33 PM
Execute another perl script from my perl script Petterson Mikael Perl Misc 3 01-05-2005 01:31 PM
Can i execute aspx file in my asp pag with server.execute method(sorry) Savas Ates ASP General 1 08-17-2004 04:52 PM
Execute 0r Call Perl from within Java lord0 Java 0 04-07-2004 12:01 PM



Advertisments