system (date) in perl

A

Alexandre Jaquet

Hi I can't find why I'm getting Bad file descriptor when I use :

my $time_start = system "date \"+%H:%M:%S\"";
warn "date \"+%H:%M:%S\""; --> date "+%H:%M:%S"

thx
 
P

Paul Lalli

Alexandre Jaquet said:
Hi I can't find why I'm getting Bad file descriptor when I use :

my $time_start = system "date \"+%H:%M:%S\"";
warn "date \"+%H:%M:%S\""; --> date "+%H:%M:%S"

Unquoted string "date" may clash with future reserved word at - line 2.
String found where operator expected at - line 2, near "date
"+%H:%M:%S""
(Do you need to predeclare date?)

1) Post real code.
2) Even after removing what appears to be your pseudo code for a
comment, I do not get any messages about a "bad file descriptor".
Therefore, your problem lies elswhere. Please post a short *but
complete* program that exhibits this problem. (Have you read the
Posting Guidelines that are posted here twice weekly?)

Paul Lalli
 
P

Peter Wyzl

Alexandre Jaquet said:
Hi I can't find why I'm getting Bad file descriptor when I use :

my $time_start = system "date \"+%H:%M:%S\"";
warn "date \"+%H:%M:%S\""; --> date "+%H:%M:%S"

localtime is your friend.. it is a Perl builtin function for what you
want...

P
 
T

Tintin

Alexandre Jaquet said:
Hi I can't find why I'm getting Bad file descriptor when I use :

my $time_start = system "date \"+%H:%M:%S\"";
warn "date \"+%H:%M:%S\""; --> date "+%H:%M:%S"

No need to fork an external, unportable process

use POSIX 'strftime';
my $time_start = strftime "%T",localtime;
 
A

Alexandre Jaquet

Tintin a écrit :
No need to fork an external, unportable process

use POSIX 'strftime';
my $time_start = strftime "%T",localtime;

thanks but I could not find the way to get exactly the same I've when
I execute the command date "+%H:%M:%S" on unix system
 
A

Alexandre Jaquet

Alexandre Jaquet a écrit :
Tintin a écrit :


thanks but I could not find the way to get exactly the same I've when
I execute the command date "+%H:%M:%S" on unix system

I found it simply pass the same argument :
return strftime "%H:%M:%S",localtime;
 
T

Tintin

Alexandre Jaquet said:
Tintin a écrit :

thanks but I could not find the way to get exactly the same I've when
I execute the command date "+%H:%M:%S" on unix system

$ uname -sr
Linux 2.4.18-18.8.0
$ cat foo
#!/usr/bin/perl
use POSIX 'strftime';
print strftime("%T",localtime) . "\n";
system "date +%H:%M:%S";
$ perl foo
20:41:05
20:41:05
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,458
Latest member
Chris#

Latest Threads

Top