Unix shell access from Perl script

Reply

Join Date: Jun 2006
Posts: 263
Reputation: Mushy-pea is an unknown quantity at this point 
Solved Threads: 1
Mushy-pea's Avatar
Mushy-pea Mushy-pea is offline Offline
Posting Whiz in Training

Unix shell access from Perl script

 
0
  #1
Sep 30th, 2006
Hello everyone. I am writing a Perl script that will be installed on a Linux host. I need the script to be able to access the current time / date environment variable somtimes. I've looked through a list of the standard CGI variables that can be accessed through $ENV but time / date isn't one of them. Is it possible to pass commands to the host's shell from within a Perl script and have the result piped back into the script? If so I could just pass:

  1. date

Or maybe there is a simpler way to do this that I'm missing. Any advice would be appriciated.

Steven.
The one question you should not ask when teaching a new language structure is "Do you understand?". Do you understand?
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: Unix shell access from Perl script

 
1
  #2
Sep 30th, 2006
There are a few ways to get the date/time with perl:

http://perldoc.perl.org/functions/gmtime.html

http://perldoc.perl.org/functions/localtime.html

http://perldoc.perl.org/functions/time.html

or you can use backtiks to get the date from the system date function, something like:

my $date = `/bin/date +"%a, %b %d, %Y"`;
Last edited by KevinADC; Sep 30th, 2006 at 5:59 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 263
Reputation: Mushy-pea is an unknown quantity at this point 
Solved Threads: 1
Mushy-pea's Avatar
Mushy-pea Mushy-pea is offline Offline
Posting Whiz in Training

Re: Unix shell access from Perl script

 
0
  #3
Sep 30th, 2006
Thanks Kevin. I'm sure one of those methods will do the job.

Steven.
The one question you should not ask when teaching a new language structure is "Do you understand?". Do you understand?
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 66
Reputation: lordspace is an unknown quantity at this point 
Solved Threads: 4
lordspace's Avatar
lordspace lordspace is offline Offline
Junior Poster in Training

Re: Unix shell access from Perl script

 
0
  #4
Oct 1st, 2006
you may use also:

  1. print scalar localtime();

Svet
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC