473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 3541
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

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

Similar topics

2
by: Ben Chivers | last post by:
I have a problem, which I think can be easily solved somehow. I am trying to execute a C program through using a PHP script. I do this by sending an exec command from the PHP script. My PHP...
6
by: Kkaa | last post by:
I'm using the os.system command in a python script on Windows to run a batch file like this: os.system('x.exe') The third-party program x.exe outputs some text to the console that I want to...
9
by: Clodoaldo Pinto Neto | last post by:
Output from the shell: $ set | grep IFS IFS=$' \t\n' Output from subprocess.Popen(): "IFS=' \t\n" Both outputs for comparison:
2
by: Gerard Flanagan | last post by:
Hello, I have a third party shell script which updates multiple environment values, and I want to investigate (and ultimately capture to python) the environment state after the script has run....
5
by: Muffin | last post by:
I am trying to capture the out put of a command line program. Let say ping or maybe better yet nslookup. I would like to launch and then capture all the output , redirect it I guess to a string...
2
by: jdbartlett | last post by:
I'm trying to capture output from a command line utility (XMLSec), but only get an empty result. If I call the script from the command line, I see XMLSec's output, but I can't seem to capture it!...
16
by: Okonita via DBMonster.com | last post by:
Hi all, I am comming along with all this Linus/DB2/scripting business...I am no longer scared of it!! (LOL). But, I need to create a .ksh script that does a REORGCHK and output only tables...
13
by: Jim Langston | last post by:
I had asked this in comp.lang.c++ with out any answers that would actually work, so I'm hoping someone here may know a way. I am calling C library functions that want to output to stdout. I need...
1
by: afelotreyu | last post by:
Hello, I currently have an application in perl that starts a text based torrent client, once I give the necessary parameters to the torrent.exe it will start printing out the following information...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.