Shawn H Corey wrote:
On 11-04-05 09:24 AM, ANJAN PURKAYASTHA wrote:
Hi,
Is there any way to run a shell command from within a perl script and
capture the output in, say, an array?
One can run a shell command through the system function. But system
itself
just returns a status code.
You could
On 4/5/11 Tue Apr 5, 2011 7:11 AM, "Chap Harrison"
scribbled:
> On Apr 5, 2011, at 8:49 AM, Shawn H Corey wrote:
>
>> You could use open:
>>
>> #!/usr/bin/env perl
>>
>> use strict;
>> use warnings;
>>
>> open my $ls_fh, '-|', 'ls' or die "could not open `ls`: $!\n";
>> chomp( my @files = <
On 11-04-05 10:11 AM, Chap Harrison wrote:
Is there any reason not to just use qx?
If you use open, any error is in $! which gives you somewhere to start
looking if something goes wrong. If you use qx() or back-ticks, any
error is in $? which is the child error. This is not an error message
On 05/04/2011 15:11, Chap Harrison wrote:
Is there any reason not to just use qx?
#!/usr/bin/env perl
use strict;
use warnings;
chomp(my @files = qx(ls));
print "@files\n";
Hi Chap
Just being picky, this will print all of the output lines on a single
line separated by spaces. Since you pro
On 05/04/2011 14:24, ANJAN PURKAYASTHA wrote:
Is there any way to run a shell command from within a perl script and
capture the output in, say, an array?
One can run a shell command through the system function. But system itself
just returns a status code.
You should read the section on qx/STR
On Apr 5, 2011, at 8:49 AM, Shawn H Corey wrote:
> You could use open:
>
> #!/usr/bin/env perl
>
> use strict;
> use warnings;
>
> open my $ls_fh, '-|', 'ls' or die "could not open `ls`: $!\n";
> chomp( my @files = <$ls_fh> );
> close $ls_fh or die "could not open `ls`: $!\n";
>
> print "@file
thank you all!
Anjan
On Tue, Apr 5, 2011 at 9:49 AM, Shawn H Corey wrote:
> On 11-04-05 09:24 AM, ANJAN PURKAYASTHA wrote:
>
>> Hi,
>> Is there any way to run a shell command from within a perl script and
>> capture the output in, say, an array?
>> One can run a shell command through the system
On 11-04-05 09:24 AM, ANJAN PURKAYASTHA wrote:
Hi,
Is there any way to run a shell command from within a perl script and
capture the output in, say, an array?
One can run a shell command through the system function. But system itself
just returns a status code.
You could use open:
#!/usr/bin/
Hi Anjan
You can execute shell command inside "``" and capture the output in
variable . e,g:
--
$, = " ";
$ls = `ls`;
print $ls;
@ls = split(/\n/,$ls);
print @ls;
--
Thanks
Sunita
-Original Message-
From: ANJAN PURKAYASTHA [mailto:anjan.purkayas...@gmail.
On Tue, Apr 5, 2011 at 6:54 PM, ANJAN PURKAYASTHA <
anjan.purkayas...@gmail.com> wrote:
> Hi,
> Is there any way to run a shell command from within a perl script and
> capture the output in, say, an array?
> One can run a shell command through the system function. But system itself
> just returns
10 matches
Mail list logo