PDA

View Full Version : Someone please ans this doubt!!


shuchi
04-07-03, 05:13
Hi all

I have been posting many questions here but havent recieved a reply for most of them lately.
Anyway wanted to know that in perl if i do something like

system(dos command)
then is there any way i can store the result returned to the prompt in an external text file for later use.
for eg if i say system("dir c:") and i want the result to be stored in any external text file. is it possible..

While executing isql command its possible by saying
open(ISQL,"isql -s servername blah blah blah..")
@array=<ISQL>

then @array has the whole result saved but can a similar thing be done for any other dos command?
please please let me know its v v urgent

-shuchi

Bernd Dulfer
04-08-03, 07:30
Easiest way is to use backticks:

my @files = `dir c:`;

Those quotes are the ones that lean to the left. The string is executed as system command and the output is stored in the array.

See:
perldoc perlfaq8 - Why can't I get the output of a command with system()?

thebap
04-08-03, 12:28
Use the redirect symbol to output to a file...

eg:

system("dir c: > output.txt");