Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Choosing the path based on the system "uname" command

Reply
Thread Tools

Choosing the path based on the system "uname" command

 
 
doni
Guest
Posts: n/a
 
      02-27-2007
Hi,

I want to write a program that does check the appropriate system path
for perl in FreeBSD and Linux.

The path where I have it in FreeBSD is
#! /usr/local/bin/perl

and the path where it is in Linux is
#! /usr/bin/perl

I wanted the program to check for the uname of the system and choose
the appropriate path. Can anyone tell me how can I have my program
check this.

This is how I wrote the program but it doesnt work.

#! /usr/local/bin/perl

use strict;
use warnings;

if (system("uname") eq "Linux") {
#! /usr/bin/perl
}

< rest of the code >

Thanks,
doni

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      02-27-2007
On Feb 27, 2:49 pm, "doni" <doni.se...@gmail.com> wrote:
> Hi,
>
> I want to write a program that does check the appropriate system path
> for perl in FreeBSD and Linux.
>
> The path where I have it in FreeBSD is
> #! /usr/local/bin/perl
>
> and the path where it is in Linux is
> #! /usr/bin/perl
>
> I wanted the program to check for the uname of the system and choose
> the appropriate path. Can anyone tell me how can I have my program
> check this.
>
> This is how I wrote the program but it doesnt work.
>
> #! /usr/local/bin/perl
>
> use strict;
> use warnings;
>
> if (system("uname") eq "Linux") {


What do you think that does?

Please read the documentation for the function you're using

perldoc -f system
perldoc -q system


> #! /usr/bin/perl


That's a comment, and nothing more. The #! syntax means nothing
unless it's the first two characters of the file.

You probably meant to do an exec()

perldoc -f exec

And to avoid an infinite loop, you'll need to make sure you're not
already executing the version you meant to. I think you'll need both
the $0 and $^X variables. You can read about them in:
perldoc perlvar
In fact, you could probably get rid of the call to uname entirely, by
using the $^0 variable, also documented in that perldoc.

Hope that helps,
Paul Lalli

 
Reply With Quote
 
 
 
 
J. Gleixner
Guest
Posts: n/a
 
      02-27-2007
doni wrote:
> Hi,
>
> I want to write a program that does check the appropriate system path
> for perl in FreeBSD and Linux.
>
> The path where I have it in FreeBSD is
> #! /usr/local/bin/perl
>
> and the path where it is in Linux is
> #! /usr/bin/perl
>
> I wanted the program to check for the uname of the system and choose
> the appropriate path. Can anyone tell me how can I have my program
> check this.



Easier to use a symlink or on your Freebsd box (it's probably on your
Linux box also), run 'use.perl port', then /usr/bin/perl will work
on both.
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      02-27-2007

Quoth "doni" <>:
> Hi,
>
> I want to write a program that does check the appropriate system path
> for perl in FreeBSD and Linux.
>
> The path where I have it in FreeBSD is
> #! /usr/local/bin/perl
>
> and the path where it is in Linux is
> #! /usr/bin/perl
>
> I wanted the program to check for the uname of the system and choose
> the appropriate path. Can anyone tell me how can I have my program
> check this.


This is not a Perl question. The path on the #! line is not used by
perl, but by your operating system. In general, there is no way to put
any logic into that line, though

#!/usr/bin/env perl

may do what you want. Note that it will use the perl in your current
PATH, which may be a security risk. As others have said, you are much
better off arranging for perl to be available as /usr/bin/perl, or
writing some sort of installation script that changes the #! line.

Ben

--
For far more marvellous is the truth than any artists of the past imagined!
Why do the poets of the present not speak of it? What men are poets who can
speak of Jupiter if he were like a man, but if he is an immense spinning
sphere of methane and ammonia must be silent? [Feynmann]
 
Reply With Quote
 
doni
Guest
Posts: n/a
 
      02-27-2007
On Feb 27, 2:09 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> This is not a Perl question. The path on the #! line is not used by
> perl, but by your operating system. In general, there is no way to put
> any logic into that line, though
>
> #!/usr/bin/env perl
>
> may do what you want. Note that it will use the perl in your current
> PATH, which may be a security risk. As others have said, you are much
> better off arranging for perl to be available as /usr/bin/perl, or
> writing some sort of installation script that changes the #! line.
>
> Ben


Thanks for your input. I will have an installation script to change
the #! line.

Thanks,
doni

 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      02-27-2007
On 2007-02-27 22:09, Ben Morrow <> wrote:
> Quoth "doni" <>:

[changing the shebang line depending on uname]
> As others have said, you are much better off arranging for perl to be
> available as /usr/bin/perl, or writing some sort of installation
> script that changes the #! line.


If you use ExtUtils::MakeMaker or Module::Build, this is done
automatically at install time.

hp


--
_ | Peter J. Holzer | Es ist ganz einfach ihn zu verstehen, wenn
|_|_) | Sysadmin WSR | man nur alle wichtigen Worte im Satz durch
| | | | andere ersetzt.
__/ | http://www.hjp.at/ | -- Nils Ketelsen in danr
 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      03-05-2007
doni schreef:

> I want to write a program that does check the appropriate system path
> for perl in FreeBSD and Linux.


which -a perl

--
Affijn, Ruud

"Gewoon is een tijger."
 
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
choosing the right microsoft certification path Dwayne Microsoft Certification 0 02-02-2009 09:44 PM
Choosing what wizard to display (or wizard steps) based on a dropDownList value Andy B ASP .Net 0 04-19-2008 11:36 AM
How get the virtual path based on the physical path? marss ASP .Net 5 09-13-2007 04:20 PM
Code bloating when choosing template argument based on cmdline input PengYu.UT@gmail.com C++ 4 07-03-2007 08:51 PM
Help in choosing which path to take MJBrown MCSE 1 11-04-2003 07:03 PM



Advertisments