CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
path in perl?

 



mike robb
Deleted

Sep 24, 2000, 11:06 AM

Post #1 of 2 (164 views)
path in perl? Can't Post

I have the following program that i have set up to run under cron - to keep the program alive.

i was trying to use the INC array to get the path correct.

i'm trying the cd as a dual command split by the ";" but i thought there was a way to set the path of the perl file so that all commands would be relative to that path.
(which works...)

?

any ideas?

#!/usr/local/bin/perl

BEGIN {
unshift(@INC, "/home/beaker/counter");
}

$proc_name="Server";
$port="6234";
$cmd="/bin/ps -elf | grep -v grep | grep $port | grep $proc_name";
open(CMD,"$cmd |") | | die "Can not issue acommand: $cmd:$!\n";
$found=0;
while(<CMD> )
{
$x=$_;
$_=~s/ / /g; # remove all extra spaces
($f,$e,$uid,$pid) = split(' ',$_);
$cmd = substr($x,64,400);
#print "uid=$uid pid=$pid cmd=$cmd\n";
$found=1;
}
close(CMD);
if ($found!=1)
{
#print "need to start process\n";
$cmd="cd /home/beaker/counter/;/usr/bin/java Server 6234 &";
open(CMD,"$cmd |") &#0124; &#0124; die "Can not issue restart command: $cmd:$!\n";
}
else
{
#print "process is going fine.\n";
}
~
~


Thanks!

--mike



Kanji
User / Moderator

Sep 24, 2000, 3:52 PM

Post #2 of 2 (164 views)
Re: path in perl? [In reply to] Can't Post

Setting your path(s) is something that needs be done via the PATH key of %ENV ( ie, $ENV{'PATH'} ), which should contain a string of all the paths you want to search for programs in seperated by colons.

ie,

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

local $ENV{'PATH'} = '/path/to/dir/1:/path/to/dir/2:/etc/etc';</pre><HR></BLOCKQUOTE>

... or a little more readable ...

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

local $ENV{'PATH'} = join( ":" => qw(
/path/to/dir/1
/path/to/dir/2
/etc/etc
) );</pre><HR></BLOCKQUOTE>

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives