Operating System - Microsoft
cancel
Showing results for 
Search instead for 
Did you mean: 

How to redirect stdout of a command in perl script.

 
Highlighted
Frequent Advisor

How to redirect stdout of a command in perl script.

Hi,

How to redirect an output generated by a command using perl in windows. ( As we do in shell scripts ls > ls.out ).
Here is my script.

$DIR="C:\\Documents and settings\\Administrator";
$COMMAND="srvinfo -ns";
# srvinfo is the command available in
# Windows2003 reskit. I have attached the
# command too.

Now need to execute the srvinfo -ns and redirect the o/p to a file called srvinfo.txt at the $DIR location.

Can you please guide me to complete this.
Thanks,
Regards,
Raghu.
5 REPLIES 5
Highlighted
Honored Contributor

Re: How to redirect stdout of a command in perl script.

The simple way would be to use a batch file like

a.bat

C:\Documents and settings\Administrator\srvinfo -ns > srv_log.txt

and just execute that a.bat file

Highlighted
Frequent Advisor

Re: How to redirect stdout of a command in perl script.

Hi,

I need to use the above said infomation inside a perl script.

-Raghu
Highlighted
Honored Contributor

Re: How to redirect stdout of a command in perl script.

its the windows batch script,

put the entire command in a text file , rename it to .bat file and execute it
Highlighted
Honored Contributor

Re: How to redirect stdout of a command in perl script.

I'm not sure why a question about perl on Windows is in the HP-UX forum, but have you tried:

system("$COMMAND > $DIR\\srvinfo.txt");
Highlighted
Frequent Advisor

Re: How to redirect stdout of a command in perl script.

Heironimus,

Since the section heading is scripting and languages, thought this is the right section, anyways Sorry for the inconvenience.

Tried the option. but it didn't work.

Thanks,
Raghu