I would think this is simple to do, but I just can't figure it out this
morning. Assume I have a function in Perl which writes some output to
STDOUT. I want to call this function from a Perl script and capture its
output in a variable.
If this was an executable or even another Perl script, I could use the
open() function. But since this is a Perl function, I can't use open().
Or can I? There's got be be a way, but my brain is just not cooperating
this morning.
Alfred 3 5510
Assuming the function returns a value (and it should):
my $var = function();
or maybe I misread...
-JB
"Alfred von Campe" <al****@110.net > wrote in message
news:4d******** *************** ***@posting.goo gle.com... I would think this is simple to do, but I just can't figure it out this morning. Assume I have a function in Perl which writes some output to STDOUT. I want to call this function from a Perl script and capture its output in a variable.
If this was an executable or even another Perl script, I could use the open() function. But since this is a Perl function, I can't use open(). Or can I? There's got be be a way, but my brain is just not cooperating this morning.
Alfred
---
Posted via news://freenews.netfront.net
Complaints to ne**@netfront.n et
Would something like the following work?
open FOO_IN, "perl -e \'require \"file.pl\"; &subroutine_cal l();\'"|"
or die "blah blah blah";
while (<FOO_IN>) {...}
close FOO_IN;
- Jerry Oberle
perl -e 'printf "mailto%c%s%c%s %cchase%ccom%c" , 58, "Gerard", 46,
"Oberle", 64, 46, 10;'
> Would something like the following work? open FOO_IN, "perl -e \'require \"file.pl\"; &subroutine_cal l();\'"|" or die "blah blah blah";
while (<FOO_IN>) {...} close FOO_IN;
Probably (I haven't tested it), but this solution is even uglier than
what I had originally done :-) . It looks like I did not miss something
obvious; this functiononality does not exit in Perl. Basically, what I
want to do is to temporarily assign STDOUT to a Perl variable, so that
everything written to stdout is put in that variable.
Alfred This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Phil Powell |
last post by:
<?php
class FileRemoval {
var $fileNameArray, $isRemoved, $errorMsg = '';
function FileRemoval() { // CONSTRUCTOR
$this->fileNameArray = array();
$this->isRemoved = 0;
}
|
by: Michael W. Cocke |
last post by:
This is probably incredibly obvious, but I'm just not getting it. I
need to accept an arg (I don't care if it's from getopt or @ARGV).
and I need to be able to print to STDOUT. So far, so good. If I try
to redirect STDOUT to a file (>test.out), the program doesn't output
anything at all (I cannot even tell if it's executing) . If I don't
take the arg from the command line, the STDOUT redirect works fine.
How do I manage both?
...
|
by: max(01)* |
last post by:
hi.
i was wondering, what's the simplest way to echo the standard input to
the standard output, with no modification.
i came up with:
....
while True:
try:
|
by: Jacek Pop³awski |
last post by:
Popen from subprocess module gives me access to stdout, so I can read
it. Problem is, that I don't know how much data is available... How can
I read it without blocking my program?
example:
--------------------------------------------------------------------
import subprocess
import time
command="ls -l -R /"
|
by: Pete |
last post by:
I having a problem reading all characters from a file. What I'm trying to
do is open a file with "for now" a 32bit hex value 0x8FB4902F which I want
to && with a mask 0xFF000000 then >> right shift 24 bits storing in result
then printing the result.
I thing a while or for loop is needed but I'm not quite sure how to go about
it. How do I step through each character in this case and store it for use
and passing to another function.
...
| |
by: ElderGeek |
last post by:
Hi, all.
I am coding in C on Linux, and using an external library provided by others. This library generates a batch of error/warning messages to stdout, which I do not want to see.
Before each function call to the external library, I can insert the following:
freopen("/dev/null", "w", stdout);
However, after the function call I cannot figure out how to reroute stdout to the console.
I tried early in the program defining:
FILE...
|
by: rdabane |
last post by:
Hi,
I'm trying to perform following operation from inside the python
script
1. Open a shell ( start a process )
2. Send command1 to the process
3. Get output from the process
4. Send command2 to the process
5. Get output from the process
.......
|
by: =?ISO-8859-1?Q?Richard_Sim=F5es?= |
last post by:
Hopefully, this explanation will sufficiently clear despite the lack
of code.
I wrote a python script that takes data via stdin, does stuff with the
data, and outputs the result to stdout. A friend wrote a perl script
that opens a pipe to my script, feeds it data, and then accepts the
result. The problem here is that the python script's outputting the
result to stdout via print statements isn't doing what we expected: my
friend's perl...
|
by: Lincoln Yeoh |
last post by:
Hi,
I've just started to learn python (I've been using perl for some years).
How do I redirect ALL stderr stuff to syslog, even stderr from
external programs that don't explicitly change their own stderr?
Say I have a program called foo:
#!/usr/bin/python
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |