RE: calling a external program

2005-11-02 Thread LeFevre, Ken




Marcus:
 
Here's some code that will execute your command and 
return what would normally go to STDOUT to the array 
@lines.
 
my $path = “\\”;
my $cmd = 
“dir $path";my 
@lines;open X, "$cmd |";   @lines = ;close 
X;
 
foreach my $line 
(@lines){   print "$line\n";    }
 
Ken

  -Original Message-From: 
  [EMAIL PROTECTED] 
  [mailto:[EMAIL PROTECTED]On Behalf Of 
  MarkusSent: Wednesday, November 02, 2005 3:40 AMTo: 
  perl-win32-users@listserv.ActiveState.comSubject: calling a 
  external program
  
  Hi 
  all,
   
  I’m looking for a way to call an 
  external program and get back the result in an array without seeing anything 
  on the STDOUT.
  If ‘m using in example 
  
   
  $path = 
  “\\”;
  $result = system(“dir”, 
   $path);
   
  I can see the output on the STDOUT 
  but I can’t find a way to put it in an array to make a post 
  processing.
  Only to forward the STDOUT to a 
  file is a idea, but based on other reasons not useful for 
  me.
  The variable $result contain only 
  the return code if the external program us supporting 
  this.
   
  Markus
   
   
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: calling a external program

2005-11-02 Thread Karl-Heinz Kuth

Hi Markus,

I’m looking for a way to call an external program and get back the 
result in an array without seeing anything on the STDOUT.


If ‘m using in example

$path = “\\”;

$result = system(“dir”,  $path);

 

I can see the output on the STDOUT but I can’t find a way to put it in 
an array to make a post processing.


Only to forward the STDOUT to a file is a idea, but based on other 
reasons not useful for me.


The variable $result contain only the return code if the external 
program us supporting this.


try something like:

@output = `$externel_program 2>&1`;
$return_code = ($? >>8); # if needed

With "2>&1" you will get STDOUT and STDERR in the array @output. 
Otherwise STDOUT would be ignored and you will only see it on the display.


Hope it helps
Karl-Heinz



___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs