Answer» I wrote a perl script that reads in the date from file from system("echo %date%>>date.txt") because I cant find a way to pass it directly to a string variable such as $string
I am looking for a way to pass directly echo'd content from system commands to variable instead of having to write to hard drive as a transport of this information from shell to perl. Would like to pass directly through RAM if possible the contents directly to variable from shell.
Below is an attempt to make it work that doesnt work as intended, but runs without error on WINDOWS platform.
Code: [Select]# -- Below Compiles but with wrong results displays date but does not pass date to string variable.
$string = system("echo %date%"); print $string; # -- Prints 0 instead of SAY Tue 06/02/2009 ** I have this working by writing to a txt file and having perl open the text file and read the contents into a list array, but would like to avoid constant read/write of DATA to hard drive and instead find a better way to do this.
And instead of using a built in COMMAND in perl to get the date, I also want to find out how to get the echo'd content passed directly to a variable for other dos function ascii string outputs to be able to be passed to a variable so that this information can be read by the program and perform accordingly based on the GIVEN output from system read in.
This can be done writing to a file like I already have working, but i am looking for a way to do this without writing to hard drive. If it has to write to a drive...maybe I should look into creating a RamDrive to trick it into writing the file to memory.
Suggestions and solutions greatly appreciated!I haven't used perl in ages, but I believe that if you enclose then command in "backticks" (`) that perl will execute the command and return the output.
Just have to install activePerl again and confirm this...
yep!
here, this one seems to work:
Code: [Select]#!/usr/bin/perl # -- Below Compiles but with wrong results displays date but does not pass date to string variable.
$string = `echo %date%`; print $string;
anything in backticks is run and the output saved to the variable! Cool, huh?
"""NICE""" Easier than I expected... Many Thanks!!! you are using Perl, so use Perl. you don't need to use system command to put the date into a string. Use Perl's own date functions. eg localtime type perldoc -f localtime to see examples.
there are also various modules you can use , DateTime, Date::Calc, Date::ManipQuite true.
|