Hi,

I am trying to write the output generated by a simple command "dir" to a file. Can you please help me do that?

Here is what I am doing --

system ("dir");

this will run dir command on my D: drive now, I want to write this ouput (in short whatever is displayed on cmd) to file. How can I do that?

you mean you want to save the information displayed on your
command prompt to an msword or notepad file?

Next time I would prefer to see some effort to solve your programming reqirements before posting code. Here is one way it can be done:

my $dir = qx{dir};
open (my $OUT, ">", 'dir.txt') or die "$!";
print $OUT $dir;
close $OUT;

Sure.... thanks so much for the help. Actually I am a beginner of per and I was using only system command and was not aware of qx.

Thanks...

As a beginner you should read the documentation for functions and modules and such things as you try and use them. You would notice that system() does not return any application output back to your perl script.

If you don't know how to read the perl documentation locally, you can read it online:

http://perldoc.perl.org/

the version you have installed locally may not be the latest version of perl, which the online documentation is. But most of the core functions are still the same.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.