I'd like to capture the stdout output from system("command ")
in a buffer. Although system("command >tmpnam") and then
open,read,remov e tmpnam works, it's a bit more messy than
I'd like. Is there any way to redirect system()'s stdout
directly to an internal memory buffer before issuing the call?
Thanks,
--
John Forkosh ( mailto: j@f.com where j=john and f=forkosh ) 6 8830
In article <fd**********@r eader1.panix.co m>,
JohnF <jo***@please.s ee.sig.for.addr ess.comwrote:
>I'd like to capture the stdout output from system("command ") in a buffer. Although system("command >tmpnam") and then open,read,remo ve tmpnam works, it's a bit more messy than I'd like. Is there any way to redirect system()'s stdout directly to an internal memory buffer before issuing the call?
Not within Standard C. Recall that *all* the C standards say
about the interpretation of the system() command is that
you can probe for the -existance- of an interpreter by passing
the NULL pointer: otherwise, what happens about the string is
completely system dependant.
If you are assuming that the system() command has a mechanism
for producing some kind of useable output, then you are making
a non-portable assumption, and so you might as well go ahead and
add in some kind of more blatant non-portability that does the
job you need. For example, if you are on a system with POSIX
extensions, you could (at no loss of portability since what you
want to do is non-portable anyhow) use popen() .
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
On Fri, 21 Sep 2007 16:22:07 +0000, Walter Roberson wrote:
In article <fd**********@r eader1.panix.co m>,
JohnF <jo***@please.s ee.sig.for.addr ess.comwrote:
>>I'd like to capture the stdout output from system("command ") in a buffer. Although system("command >tmpnam") and then open,read,rem ove tmpnam works, it's a bit more messy than I'd like. Is there any way to redirect system()'s stdout directly to an internal memory buffer before issuing the call?
Not within Standard C. Recall that *all* the C standards say
about the interpretation of the system() command is that
you can probe for the -existance- of an interpreter by passing
the NULL pointer: otherwise, what happens about the string is
completely system dependant.
If you are assuming that the system() command has a mechanism
for producing some kind of useable output, then you are making
a non-portable assumption, and so you might as well go ahead and
add in some kind of more blatant non-portability that does the
job you need.
There are different systems where system("foo bar") executes
foo placing its output in bar. One might write code portable
across those but not elsewhere. "Either portable everywhere or
useful on only one architecture" is a false dilemma (look up
Wikipedia). (Anyway, I can not think of a way to do what the OP
wants on all those systems, so, if he only wants to support one
architecture, he should ask in a group about it.)
--
Army1987 (Replace "NOSPAM" with "email")
If you're sending e-mail from a Windows machine, turn off Microsoft's
stupid “Smart Quotes” feature. This is so you'll avoid sprinkling garbage
characters through your mail. -- Eric S. Raymond and Rick Moen
Walter Roberson <ro******@ibd.n rc-cnrc.gc.cawrote :
JohnF <jo***@please.s ee.sig.for.addr ess.comwrote:
>>I'd like to capture the stdout output from system("command ") in a buffer. Although system("command >tmpnam") and then open,read,rem ove tmpnam works, it's a bit more messy than I'd like. Is there any way to redirect system()'s stdout directly to an internal memory buffer before issuing the call?
Not within Standard C. Recall that *all* the C standards say
about the interpretation of the system() command is that
you can probe for the -existance- of an interpreter by passing
the NULL pointer: otherwise, what happens about the string is
completely system dependant.
If you are assuming that the system() command has a mechanism
for producing some kind of useable output, then you are making
a non-portable assumption, and so you might as well go ahead and
add in some kind of more blatant non-portability that does the
job you need. For example, if you are on a system with POSIX
extensions, you could (at no loss of portability since what you
want to do is non-portable anyhow) use popen() .
Thanks, Walter, ditto Army1987.
Looks to me like popen() will work fine. I'm basically
concerned about Unix and Windows. And a little googling seems
to suggest most Windows compilers support popen(), though there
appear to be a few obscure differences in behavior that
someone or other occasionally tripped over.
Thanks, again, for bringing popen() to my attention.
--
John Forkosh ( mailto: j@f.com where j=john and f=forkosh )
Although /off-topic/ you may find it is named _popen() on Windows. st************* @googlemail.com wrote:
Although /off-topic/ you may find it is named _popen() on Windows.
Terrific. Another #ifdef for Windows.
Just what I wanted.
--
John Forkosh ( mailto: j@f.com where j=john and f=forkosh )
On 23 Sep, 16:09, JohnF <jo...@please.s ee.sig.for.addr ess.comwrote:
stephenwvick... @googlemail.com wrote:
Although /off-topic/ you may find it is named _popen() on Windows.
Terrific. Another #ifdef for Windows.
Just what I wanted.
--
John Forkosh ( mailto: j...@f.com where j=john and f=forkosh )
Come on, you wouldn't expect anything else would you? :-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tsai Li Ming |
last post by:
Dear all,
I have a problem with a redirecting stdout and stderr. I am a top level
module and has no control over the imported modules that are making
system calls such as os.system or popen2.* . I have tried the simplest
method of capturing stdout, stderr via:
saveout = sys.stdout
sys.stdout = file_obj
|
by: Paul Nilsson |
last post by:
Hi,
Does anyone know how to redirect text output when issuing a system or an
execlp call? I have a GUI that insists on opening up a console whenever I
give a system function call, and I would like to redirect the text output to
a char buffer instead.
Paul
|
by: Michael Gaab |
last post by:
If I redirect stdout by using freopen("afile", "w", stdout);
and then I closed stdout using, fclose(stdout), essentially I am just
closing "afile".
I have to reestablish what stdout originally pointed to?
thanks
|
by: mboyda |
last post by:
I have a block of code that useses outputstream to save a pdf to a
client computer. It prompts the user with the save dialog, works
great but the response finishes after the download completes. How do
I redirect the users to a new friendly page after the download
completes. The aspx page comes back with a ugly "action canceled". I
prefer not to use popup windows as alot of people are blocking them.
I just want them to click a download...
|
by: mikem76 |
last post by:
How do I automatically redirect stdout and stderr when using os.popen2
to start a long running process. If the process prints a lot of stuff
to stdout it will eventually stop because it runs out of buffer space.
Once I start reading the stdout file returned by os.popen2 then the
process resumes. I know that I could just specify > /dev/null when
starting the process but I'd like to know if there is a way to start a
process using os.popen2...
| |
by: cmk128 |
last post by:
Hi
here is my c file, compile in gcc 3.X in linux:
#include <stdio.h>
int main()
{
printf("Hello\n");
if (fork() == 0) printf("world! \n");
}
|
by: ws.taylor |
last post by:
I am in a systems programming class, using C on a Solaris 10
development server. Part of the first programming assignment calls for
the output of a command executed by a child process with execvp to be
redirected to a buffer so that it can be sent through a named pipe back
to the parent process. The only part I'm having problems with is
capturing execvp's output to a buffer. I can't find anything about this
from our book, or from searching...
|
by: Alejandro |
last post by:
Hi:
I want to redirect stdout to a textctrl I have. From what I read in
the wxpython documentation, I can use the wxLogTextCtrl class to do
this. I am doing the following:
class MyGui(gui.MyFrame): #gui.MyFrame generated by wxGlade
def __init__(self, *args, **kwds):
gui.MyFrame.__init__(self, *args, **kwds)
# ... code removed ...
|
by: loketing |
last post by:
Is there any way to redirect the output of the system() function? I know there is for redirecting stdout, but I can't make this work with system().
I tried to store the output of a system command in a file, like so:
FILE *File = NULL;
freopen_s(&File, "somefile.txt", "w", stdout);
system ("dir");
fclose(stdout);
...but this doesn't help. Is there any way to do this?
Thank you.
|
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look !
Part I. Meaning of...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |