Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

System call on MSDos

by Zo (Scribe)
on Feb 27, 2002 at 19:58 UTC ( #148018=perlquestion: print w/replies, xml ) Need Help??

Zo has asked for the wisdom of the Perl Monks concerning the following question:

Hello all...
I've searched and searched before asking here and found nothing, so here I go...

I am trying to catch the system date on a Windows2000 server. When I do this, it works:

<code>print system("DATE /T");<code>
I see Wed 2/27/2002

But I want to capture the input and use it to print to a text file.. such as:
$x = system("DATE /T");
print FILENAME $x;


but what I get in the text file is the number zero (0).

Any ideas, thoughts, etc?
FYI- Win2000, ActiveState Perl 5.6...
thanks in advance for all help.

Zo.

Replies are listed 'Best First'.
Re: System call on MSDos
by data64 (Chaplain) on Feb 27, 2002 at 20:37 UTC

    Any reason not to use localtime to get the system date ?

    There is also a Time::localtime which you can use.

    ($day, $month, $year) = (localtime)[ 3, 4, 5 ];

    The problem with what you are trying to do is that you need to use backticks or the qx operator if you want to trap the output of the command. The 0 you see in the text file is the return value from system, which is giving you the status of the call and not what the call wrote to its standard output.

    $date = `Date /T`; print FILENAME $date;

    <cite>Just a tongue-tied, twisted, earth-bound misfit. -- Pink Floyd</cite>

Re: System call on MSDos
by JayBonci (Curate) on Feb 27, 2002 at 20:38 UTC
    This is offtopic for perl, but file redirects work in DOS. Therefore, date /t > outfile.txt would output it to outfile.txt in the same directory. You can give it a path to go where you'd like.

    Just another way that you can get the job done...    --jay

      Aack! Stuff like this is fraught with peril. Don't do it!

      What if the user had a valuable file of the same name in that directory that you just clobbered? What if you don't have permission to write in the directory? What if someone in a different timezone has mounted the drive remotely and runs at the same time as you do? What if any of a number of ugly things happen between the time you write it and the time you read it?

      This creates a maintenance headache way out of proportion to the problem you're trying to solve. Polluting a directory to get the date is completely unnecessary, and is an accident just waiting to happen.

      But now let me tell you how I really feel ;-)

      You're right of course about redirecting the output. But, sorry to nitpick, this isn't DOS exactly - it's the WinNT shell. DOS, as seen on Windows9x/3x/MS-DOS won't take the switch /t after the date command.
Re: System call on MSDos
by Zo (Scribe) on Feb 27, 2002 at 20:40 UTC
    I will try both the backtick and the Localtime
    Thank you much!

    Zo.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://148018]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2019-05-20 02:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (123 votes). Check out past polls.

    Notices?