Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing a system command

Status
Not open for further replies.

kirk124

Programmer
Apr 15, 2003
26
US
Hi,

Is there a way to execute a system command and read the output through a while loop using the back tick.

Normally I excute a command like this.

ie

System("ls > ls.txt");
open RI,&quot;<ls.txt&quot; || die &quot;can't open ls.txt: $!\n&quot;;

while(.....)
{
print(&quot;$line\n&quot;);
}

thanks
 
this will put the output from the system command into array @foo

@foo = `ls`;

for (@foo){
print $_;
}
 
Not quite, but you can read the command's output directly by opening it as a pipe.


# note the pipe operator in the filespec
open (RI,&quot;ls |&quot;) || die &quot;can't open ls command\n&quot;;
while($line = <RI>)
{
print(&quot;$line\n&quot;);
}
clsoe RI;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top