473,785 Members | 2,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I redirect stdout from system/execlp calls?

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
Jul 19 '05 #1
4 10043
On Fri, 3 Oct 2003 18:38:53 +0200, "Paul Nilsson"
<Pa**********@c ern.ch> wrote:
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.


comp.unix.progr ammer might be a better place to ask, since standard
C++ has no methods to interact with consoles or any way to launch
processes other than "system".

Tom
Jul 19 '05 #2
WW
Paul Nilsson wrote:
Hi,

Does anyone know how to redirect text output when issuing a system
system("a command with output redirected");
or an execlp call?
There is no execlp in standard C++: http://www.slack.net/~shiva/welcome.txt
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.


It will possibly still open a console. You will need to post your question
to a newsgroup dedicated to your platform/compiler:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

--
WW aka Attila
Jul 19 '05 #3
In article <bl*********@su nnews.cern.ch>, Pa**********@ce rn.ch says...
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.


Find a newsgroup devoted to the OS you're using, and ask them about
popen -- it's likely to be available, and if it's not, there are at
least likely to be some people who will recognize the name and know what
to advise as an alternative.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 19 '05 #4
"Jerry Coffin" <jc*****@taeus. com> wrote in message
news:MP******** *************** *@news.clspco.a delphia.net...
In article <bl*********@su nnews.cern.ch>, Pa**********@ce rn.ch says...
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.
Find a newsgroup devoted to the OS you're using, and ask them about
popen -- it's likely to be available, and if it's not, there are at
least likely to be some people who will recognize the name and know what
to advise as an alternative.


Hi,

Thanks, aparently this only works for console applications. However, the
MSVC++7 documentation for the popen function links to a document showing how
to do with a windows application as well! So you helped me anyway! Thanks,
Paul

--
Later,
Jerry.

The universe is a figment of its own imagination.

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3583
by: Melissa Wallis | last post by:
In a Python script I start a number of C++ processes using os.execlp. Most of these processes output messages for debugging purposes at this time. The problem I am having is that by starting 4 or 5 processes from my Python script I don't get the cout messages they write. I have tried redirecting stdout to a file but I get everything but the output from the C++ processes. Any suggestions. Thanks Melissa
6
5639
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
4
11019
by: Excluded_Middle | last post by:
Hi, My teacher gave me an assignment to create a shell using ANSI C and system calls. The shell is going to be very simple that can handle IO redirection and pipes. so far I create a program that prompts user and read commands using scanf and then save this command in a string called cmd. then it uses fork to create a child process and then execute the command using execlp,my teacher said use execvp but it was giving me error. i.e when...
6
2567
by: Mazze | last post by:
Hi. I have a strange problem ... I want to create a process and capture stdout : ... gint std_out; char* argv = {"/opt/sun-jdk-1.4.2.08/bin/java","helloworld",NULL}; //char* argv = {"/usr/bin/du","/",NULL}; g_spawn_async_with_pipes("/work/", argv, NULL, G_SPAWN_CHILD_INHERITS_STDIN,
5
21073
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...
6
8830
by: JohnF | last post by:
I'd like to capture the stdout output from system("command") in a buffer. Although system("command >tmpnam") and then open,read,remove 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 )
2
3255
by: manontheedge | last post by:
I'm trying to write a program in C on Linux where the child processes get their process images replaced. I have in my code, a few child processes that I forked from a single parent process. I'm then attempting to replace their ( the child ) process images with separate executables. I have these executables written and placed in the directory. My problem is when I'm using execlp. When it reaches execlp in my code, it does replace the...
2
4715
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.
23
2146
by: student.matt | last post by:
ok i am trying to solve this little problem i have my program waits for the 1st system() call to finish before starting the next i will just throw an example of what i mean out in this example it waits for the 1st kedit to be closed before it opens the second #include <stdio.h> #include <stdlib.h> int main()
0
9645
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, 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...
0
10325
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, 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...
0
10147
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 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...
0
9950
tracyyun
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...
1
7499
isladogs
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...
0
6739
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();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.