Perl: Running Command line apps in background and capturing output
Hey there,
I'm trying to write a perl script that will run an app in the background (ie: so it doesn't output any text) and, instead it stores it in a variable so i can parse it and spit it out. The only things I have tried (and know of) are qx/application/; and system("application");. using both of these methods, the program does not withold the data from the screen. Unfortunately, I couldn't find any (linux) help on the net. Thanks in advance, s0l1dsnak3123 ps. Here is what I have tried: Code:
$out = system("gksu -u root \"obexftp -u ttyACX0 -v -l $dir\""); |
You have to redirect your standard output to a file instead of the std output,i.e, screen.
Linux has got a file descriptor for standard output, which is 1 (similar to the 0 for standard input file descriptor). $ ls -al 1> filelisting This will redirect output to the file instead of screen. Gentoo |
Use backquotes.
my $output = `ls -l`; |
Or use a piped open or IPC::Open2: http://perldoc.perl.org/functions/open.html
|
OK, thanks alot its working now :D
Only one problem... after doing alot of regex Code:
$out =~ s/<\?xml[^>]+?>//ig; #gets rid of <?xml*?> Code:
Code:
Pictures,Sounds,Themes,Videos,Other Code:
while ($out =~ m/\t/) { Code:
while ($out =~ m/\t/) { I have tried googling the problem, but to no avail... Please help :cry: [edit] after talking to some guys on IRC, and doing a bit of fiddling, I now have it working. Thanks anyway :D |
Quote:
|
Quote:
Code:
#!/usr/bin/perl -w |
Quote:
Code:
$out =~ s/^\s+//g; #strip all spaces at the start Quote:
|
Separate regexes are usually faster, FWIW :)
|
All times are GMT -5. The time now is 03:47 PM. |