469,336 Members | 5,556 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

how to capture output from a system call and pipe into running script?

How to I capture stdout output from a system call and pipe it back into my running script?

system "echo foobar";

# how to continue here with "foobar" in stdin ??

...

I can fake it with pipes and additional scripts, but that seems like overkill.

Thanks.
(Yes, I'm STILL a newbie!)

dave
Jul 11 '07 #1
8 3350
miller
1,089 Expert 1GB
use backticks

Expand|Select|Wrap|Line Numbers
  1. my $output = `echo foobar`;
  2. print $output; # Prints "foobar";
  3.  
- Miller
Jul 11 '07 #2
Yes indeed! Thank you!
d
Jul 11 '07 #3
KevinADC
4,059 Expert 2GB
How to I capture stdout output from a system call and pipe it back into my running script?

system "echo foobar";

# how to continue here with "foobar" in stdin ??
You can't. system() does not return stdout data back to your perl program. You can use backtiks as Miller has shown, but if you want to step through the output line by line, using a pipe is better.

A more readable form of backtiks is the qx// operator.
Jul 11 '07 #4
miller
1,089 Expert 1GB
Hey Kevin,

I'm continually annoyed whenever I want to refer people to the documentation for backticks. Instead of being at perldoc qx, you must instead go out of your way to perlop and search for qx. Is there any other location that you've found for such documentation?

- Miller
Jul 11 '07 #5
KevinADC
4,059 Expert 2GB
Well, it's kind of buried on this page:

perlop: quote and quote like operators

qx is an operator, the operators are not given a page by page listing like the functions are.
Jul 11 '07 #6
miller
1,089 Expert 1GB
I still have to say .... lame.

- M
Jul 11 '07 #7
KevinADC
4,059 Expert 2GB
I still have to say .... lame.

- M

I don't much care for it myself. It seems they could break down the operators into more specific categories and give them their own pages.
Jul 11 '07 #8
miller
1,089 Expert 1GB
Well that's the thing. They already have pages for all the quoting operators. They simply link to the perlop page.

When referencing something, it's always useful to be able to provide a direct link. But the operators do not have specific anchors, so you have to do the "search for this" instruction. I think that while a lot of the operators are related and need to be discussed en mass, it would be very useful to newbies and us teachers to be able to link directly to the specific resource.

That's all :/

- M
Jul 11 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Kkaa | last post: by
9 posts views Thread by Clodoaldo Pinto Neto | last post: by
5 posts views Thread by Muffin | last post: by
2 posts views Thread by jdbartlett | last post: by
13 posts views Thread by Jim Langston | last post: by
1 post views Thread by afelotreyu | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.