CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Capturing data of linux command using perl.

 



cuboidgraphix
User

Feb 23, 2010, 11:51 AM

Post #1 of 5 (495 views)
Capturing data of linux command using perl. Can't Post

Hi guys,
Been a while. Trying something new. I'm trying to run a linux command in my perl script and I want to capture the output into a variable. This is what I got but it's not working. Any help will be highly appreciated.


Code
#!/usr/bin/perl 

use strict;
use warnings;
use POSIX qw/strftime/;

my $date = strftime("%y-%m-%d", localtime(time));

my ($files) = system("ls vlr2010*");
print $files;



(This post was edited by cuboidgraphix on Feb 23, 2010, 11:52 AM)


toolic
User

Feb 23, 2010, 11:53 AM

Post #2 of 5 (492 views)
Re: [cuboidgraphix] Capturing data of linux command using perl. [In reply to] Can't Post


Code
my $files = qx(ls vlr2010*);


http://perldoc.perl.org/functions/qx.html


(This post was edited by toolic on Feb 23, 2010, 12:27 PM)


cuboidgraphix
User

Feb 23, 2010, 12:01 PM

Post #3 of 5 (491 views)
Re: [toolic] Capturing data of linux command using perl. [In reply to] Can't Post

Thanks for the quick response toolic.

However, when I run the command it gives me this...

sh: ls vlr2010*: command not found

I'll go ahead an also look at the link you supplied.

Does this need any 'use' statements?


(This post was edited by cuboidgraphix on Feb 23, 2010, 12:23 PM)


toolic
User

Feb 23, 2010, 12:28 PM

Post #4 of 5 (479 views)
Re: [cuboidgraphix] Capturing data of linux command using perl. [In reply to] Can't Post

No need for double quotes... see my updates.


cuboidgraphix
User

Feb 23, 2010, 12:32 PM

Post #5 of 5 (477 views)
Re: [toolic] Capturing data of linux command using perl. [In reply to] Can't Post

Perfect!

Thanks toolic. This has helped me a lot. I can now resume coding further. :) Thanks again!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives