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: Intermediate:
Backtik `date` in Windows

 



zatlas1
Novice

Jun 23, 2011, 8:38 PM

Post #1 of 5 (1435 views)
Backtik `date` in Windows Can't Post

I have a Unix Perl program that I've inherited and cannot really change (in that aspect.) It makes use of the backtik with the `date` Unix function. I need to run this program in Windows environment and program stalls when it get to this statement. For now in test, I skip this statement and produce an appropriate string (for 1/1/2000,) but I need to do better.
Is there a way to call the Windows (DOS) date routine when I sense I run in Windows (I know how to sense the OS.) If I could do that, I do not need to create the appropriate string after using localtime.
Thanks


miller
User

Jun 24, 2011, 12:46 AM

Post #2 of 5 (1432 views)
Re: [zatlas1] Backtik `date` in Windows [In reply to] Can't Post

You can do better, just use a pure perl version:


Code
use POSIX qw(strftime); 

use strict;
use warnings;

print strftime "%a %b %d %H:%M:%S %Z %Y", localtime;


Your main problem is going to be the timezone %Z, as that is not normally static cross platform. At worse, you might just want to hardcode that as PDT or whatever your appropriate timezone is.

- Miller


zatlas1
Novice

Jun 24, 2011, 4:09 AM

Post #3 of 5 (1427 views)
Re: [miller] Backtik `date` in Windows [In reply to] Can't Post

Thank you

My problem was that on windows I really needed to do "date \/T" to get what I wanted. I will use the suggetion above or something similar to code a:

sub date {...}

to replace the `date`

ZA


rovf
Veteran

Jun 24, 2011, 4:36 AM

Post #4 of 5 (1425 views)
Re: [zatlas1] Backtik `date` in Windows [In reply to] Can't Post

(1) If its enough for your job, you can call it as


Code
date /T


(2) If you need compatibility with Unix, you can install the Gnu tools for Windows, http://gnuwin32.sourceforge.net/. Make sure that your application finds the "correct" date.exe then.


zatlas1
Novice

Jun 24, 2011, 10:57 AM

Post #5 of 5 (1409 views)
Re: [rovf] Backtik `date` in Windows [In reply to] Can't Post

Thank you all. I did code a little

sub date {...} and solved the issue.

ZA

 
 


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

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