Operating System - Microsoft
1748106 Members
4963 Online
108758 Solutions
New Discussion юеВ

How to redirect stdout of a command in perl script.

 
Raghu Chikkamenahalli
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
T G Manikandan
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

Raghu Chikkamenahalli
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
T G Manikandan
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
Heironimus
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");
Raghu Chikkamenahalli
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