473,795 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Redirect system() output?

2 New Member
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:
Expand|Select|Wrap|Line Numbers
  1. FILE *File = NULL;
  2. freopen_s(&File, "somefile.txt", "w", stdout);
  3. system ("dir");
  4. fclose(stdout);
...but this doesn't help. Is there any way to do this?

Thank you.
Mar 21 '08 #1
2 4715
loketing
2 New Member
Ok, so I found one way that sort of helped. By just adding "<< somefile.txt" after the system call, I could capture the output. Like so:
Expand|Select|Wrap|Line Numbers
  1. system("dir >> somefile.txt");
However, this only partly solves my problem. A console window still opens, and executes the command before it is stored in a file. I need to disable this window from appearing as well, is there any way to do this?
Mar 21 '08 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
Why not just call the same functions that dir does and write your output to a file?
Mar 21 '08 #3

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

Similar topics

5
4283
by: Hal Vaughan | last post by:
I have a Java program, composed of a number of classes, that I've been running as a command line program. It logs everything it does and, as it logs each event, it also prints that line of info to the console. I would like to create a wrapper class to open a window, call my application, and redirect all the output to a TextField in the window. I know I could have the wrapper simply run a command line instance of the app (like "java...
4
10044
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
2
1902
by: Jason | last post by:
Hello, I have a class, transCore, that does certain work, and by default, prints its progress to the stand output. Later, I will to write a GUI class that encapsulate the transCore class. I would like to redirect/intercept the output of transCore class to this GUI class. I wrote a sample program that demonstrate how I did it, but I am not sure if it's any good. Can anyone critic my code? If there's any non-standard conforming code or...
1
2346
by: iksrazal | last post by:
Hi all, I've been struggling to make this command work from Java: /usr/bin/mysql c4 --user=root --password=mypass -e "source /home/crissilva/c4.sql" Works fine as shown when run from the shell. Using my Java program I get:
1
2986
by: Byron | last post by:
I want to take the output of a DOS console application that just streams data to the screen and redirect that output in real time into a C# application that will decode and reformat it for display. I know I could redirect from the DOS application into a file and then read the file, but I want to do this in real-time so I can affect the output of the DOS application and immediately see the results in the C# app. The DOS application is...
1
15336
by: Peter Kirk | last post by:
Hi there I have a program written by another company (it's a "web control" which returns a web-page: can I compare this to a servlet in the Java world?), which they think is causing problems on their server. But no-one really knows if this program is at fault because the problem only exhibits itself every once and a while, and the only thing they can see is that their web-users suddenly stop receiving responses.
7
43277
by: Anne | last post by:
hie there, i want to be able to pass multiple parameters to another page. currently, i am able to do so, but somehow i feel it is not the correct way to do it. below is part of what i have so far. 'first page Private Sub btnOK_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click Response.Redirect("InputValues.aspx?Requestor=" &
4
10607
by: bnob | last post by:
In a Button clik event I have this code at the end of the event Response.Redirect("Page.aspx") But in this event I must show a message before redirect to the Page.aspx. I use to show Message this System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf) System.Web.HttpContext.Current.Response.Write("alert('A message')" &
2
9546
by: Zeba | last post by:
Hi ! I am using a httphandler to perform some url rewriting in my application. My web.config contains the following entry to direct all urls containing /App/*.ashx to my class AppHandler.cs in namespace mySite.Web <httpHandlers> <add verb="*" path="App/*.ashx" type="mySite.Web.AppHandler, App_Code"/>
0
1910
by: shravagiparag | last post by:
Hello, I am developing a console application to invoke gdb session and log in the communication between my application and gdb. I opened gdb as a new process and tried to redirect the input and output of the process to a streamwriter.But its not working. I am able to redirect the standard input for the gdb process i.e. I can issue commands from my application to gdb but I am not able to redirect its standard output. The gdb process does...
0
9673
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
9522
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,...
1
10165
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,...
0
9044
agi2029
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...
0
6783
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
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2921
bsmnconsultancy
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...

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.