473,396 Members | 1,853 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,396 software developers and data experts.

Dump program results to file

I am writing a c++ program that will run multiple *.exe files and dump
the results to a file. In my test case, I am using netstat. I am
running netstat from my c++ program with the

system("netstat.exe");

command. I have already tried the following:
________________________
ofstream t;
t.open("tempp.txt");
t<<system("netstat.exe");
t.close();
________________________
The only response I am getting is that tempp.txt has a zero written in
the file. Does anyone have any ideas.

Thanks

Jul 9 '06 #1
3 2206
Reggie wrote:
I am writing a c++ program that will run multiple *.exe files and dump
the results to a file. In my test case, I am using netstat. I am
running netstat from my c++ program with the

system("netstat.exe");

command. I have already tried the following:
________________________
ofstream t;
t.open("tempp.txt");
t<<system("netstat.exe");
t.close();
________________________
The only response I am getting is that tempp.txt has a zero written in
the file. Does anyone have any ideas.
I think, the std::system( command ) call does not open a pipe to the process
running command interacting with streams. Thus, by itself, std::system()
cannot make the output of the command it runs available to the program. You
need to redirect the output of the command *within* the std::system() call.
Try something like

std::system( "netstat.exe tempp.txt" );

This has a chance of working if the OS supports pipes.

It would be nice though, if there was a function like

void std::system_bg ( char const * cmd,
std::istream & to_cmd, std::ostream & from_cmd )

in the library. It is quite possible that your platform has some support for
this using a function of another name. (That one, however, would be
off-topic in this group.)
Best

Kai-Uwe Bux
Jul 9 '06 #2
I guess my OS supported the command. Thanks, it works great.

Jul 9 '06 #3
Hi,
I think, popen could be used in this case. Basically, popen opens a
pipe to the process which can then be read like a normal file handle.

http://www.opengroup.org/pubs/online...xsh/popen.html

Thanks and regards
Sonison James
Reggie wrote:
I guess my OS supported the command. Thanks, it works great.
Jul 10 '06 #4

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

Similar topics

0
by: Guenter Walser | last post by:
Hello, When using the codeline: pickle.dump(self, file, pickle.HIGHEST_PROTOCOL) my program runs perfectly fine: --------------------------- Testprotocol -----------------------------
0
by: Johnson, Shaunn | last post by:
Howdy: Running PostgreSQL 7.3.3 on RedHat Linux 7.2 I'm trying to dump a table out with the insert statements imbedded and I'm not having any success. The man page for pg_dump says to use:...
7
by: Matt | last post by:
I want to know what is Hex Dump? I tried to search in google but didn't get useful results. I know it is the hexademical representation of something. But I don't know what is something? From C...
7
by: Cyril VELTER | last post by:
I'm trying to dump a database from a 7.1.3 server to a 7.4.2 one. It doesn't works because of difference in COPY format (unless I use -d which is VERY slow on a 16G database). What are the...
2
by: Auddog | last post by:
Hello all, I'm fairly new to access database(s), but I work a lot with mysql. I was wondering if there is a script file out there that I can get a hold of that will create a dump file. I need...
14
by: Sheldon | last post by:
Hi, I have a python script that uses a C extention. I keep getting a recurring problem that causes a core dump a few lines after the C extention return data back tp python. I tried using pbd and...
1
by: TYR | last post by:
I have a large dump file that originated in a MySQL db; I need to get it into an SQLite file. Various options are suggested around the web; none of them seem to work (most failing to import the...
7
by: Just_a_fan | last post by:
I have a program which runs fine here (created in VB9). I publish it to my web site for download & install. It runs on some computers (one or two) but not others. When it does not run, it causes...
4
by: Aidan | last post by:
Hi, I'm having a bit of trouble with a python script I wrote, though I'm not sure if it's related directly to python, or one of the other software packages... The situation is that I'm trying...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
0
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...
0
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...
0
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,...

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.