473,399 Members | 3,106 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,399 software developers and data experts.

Appending to a File using system()

I have been using the system() command to write the results of a
program to a file. This is being accomplished by the following when
running netstat for example:

system("netstat example.txt");

When I run the command again, it completely rewrites the text file with
new results. What I would like to do is run the command again and have
the results append to the text file instead of completely rewriting the
text file. I have tried several hybrid commands using <fstreambut
nothing has worked yet. Thanks for any help.

Jul 11 '06 #1
10 3144
Reggie wrote:
I have been using the system() command to write the results of a
program to a file. This is being accomplished by the following when
running netstat for example:

system("netstat example.txt");

When I run the command again, it completely rewrites the text file with
new results. What I would like to do is run the command again and have
the results append to the text file instead of completely rewriting the
text file. I have tried several hybrid commands using <fstreambut
nothing has worked yet. Thanks for any help.
This is an OS dependency, so you should ask in a group dedicated to
your OS (or in UNIX, your shell). <OT>In some environments, ">>"
appends.</OT>

Cheers! --M

Jul 11 '06 #2
Reggie wrote:
I have been using the system() command to write the results of a
program to a file. This is being accomplished by the following when
running netstat for example:

system("netstat example.txt");

When I run the command again, it completely rewrites the text file with
new results. What I would like to do is run the command again and have
the results append to the text file instead of completely rewriting the
text file. I have tried several hybrid commands using <fstreambut
nothing has worked yet. Thanks for any help.
Try

system("netstat >example.txt");
Thanks and regards
SJ

Jul 11 '06 #3
Reggie wrote:
system("netstat example.txt");

When I run the command again, it completely rewrites the text file with
new results. What I would like to do is run the command again and have
the results append to the text file
system("netstat >example.txt");

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Jul 11 '06 #4
I am using Windows XP.

Jul 11 '06 #5
Reggie wrote:
>I am using Windows XP.
mlimber (assuming that's who you replied to) mentioned topicality because
this question is off-topic for a C++ newsgroup. That means you would have
gotten the best answer on a WinXP group, not that we need to know what
platform you use.

C++ itself doesn't specify the >command line operator.

And if your program is a simple "script" that manages your netstat, you
should write it in a simpler language, such as Ruby.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Jul 11 '06 #6
Thanks for the help everyone. Adding ">>" to the command is just what
I needed.

Jul 11 '06 #7
Reggie wrote:
I have been using the system() command to write the results of a
program to a file. This is being accomplished by the following when
running netstat for example:

system("netstat example.txt");

When I run the command again, it completely rewrites the text file with
new results. What I would like to do is run the command again and have
the results append to the text file instead of completely rewriting the
text file. I have tried several hybrid commands using <fstreambut
nothing has worked yet. Thanks for any help.
Is that C++ ?
Anyway, use the one you did first time,
then next time use
system("netstat >example.txt")
Jul 12 '06 #8
As a little aside, I am having a particular trouble with the DEVCON
Windows utility
command. The following line of code always produces a "devcon failed"
error.
system("devcon -m:\\127.0.0.1 findall *");
When I run the above command at the command prompt, I do not get this
error. Any ideas as to why I am only getting an error when I use this
line in my program? I'm not sure if this is a c++ problem or a
windows32 console problem but it has me baffled.

Sjouke Burry wrote:
Reggie wrote:
I have been using the system() command to write the results of a
program to a file. This is being accomplished by the following when
running netstat for example:

system("netstat example.txt");

When I run the command again, it completely rewrites the text file with
new results. What I would like to do is run the command again and have
the results append to the text file instead of completely rewriting the
text file. I have tried several hybrid commands using <fstreambut
nothing has worked yet. Thanks for any help.
Is that C++ ?
Anyway, use the one you did first time,
then next time use
system("netstat >example.txt")
Jul 12 '06 #9
Reggie wrote:
system("devcon -m:\\127.0.0.1 findall *");
The string literal "" interprets \ as an escape code, so \\ is the escape
for a literal \. Hence, you need -m:\\\\. Four backslashes.

Next time you use system, use it like this:

string cmd = "devcon -m...";
cout << cmd << endl;
system(cmd.c_str());

Then you see what you got.

And please consider switching to a softer language for this high-level
glue stuff. C++ is best used to program big hard systems, like databases
or network servers.

--
Phlip

Jul 12 '06 #10
On Tue, 11 Jul 2006 18:03:37 -0700, Reggie wrote:
As a little aside, I am having a particular trouble with the DEVCON
Windows utility
command. The following line of code always produces a "devcon failed"
error.
system("devcon -m:\\127.0.0.1 findall *");
When I run the above command at the command prompt, I do not get this
error. Any ideas as to why I am only getting an error when I use this
line in my program? I'm not sure if this is a c++ problem or a
windows32 console problem but it has me baffled.
A) Don't top-post.

B) Don't post off-topic questions; this'd be more appropriate in a Windows
programming newsgroup than in a language newsgroup.

C) Fortunately, there is a C++ issue here: Are you *sure* you're typing
the same command as you're passing to system? Hint:
printf("devcon -m:\\127.0.0.1 findall *");

Jul 12 '06 #11

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

Similar topics

1
by: dmiller23462 | last post by:
Hey guys.... I put an error-handling in my page and have it posted at the complete end of the code, see below(when people were putting in 's I was getting the delimiter errors). Great, I...
16
by: Michael | last post by:
I have a data application in a2k that I need to create two fixed width text files and then combine them to a single file The first file is header information and the second is transaction data. ...
1
by: Anna Warloe | last post by:
This might be a dumb question, but I am pretty new to Access.... I am trying to write code in Access to take river forecasts which are delivered as attachments in emails and append the data into...
3
by: MLH | last post by:
I have a query, qryAppend30DayOld260ies that attempts to append records to tblCorrespondence. When run, it can result in any of the following: appending no records, appending 1 record or appending...
3
by: Mike P | last post by:
Does anybody have a simple example of appending text to a text file? Cheers, Mike *** Sent via Developersdex http://www.developersdex.com ***
2
by: tony.collings | last post by:
I started a thread here : http://groups.google.co.uk/group/microsoft.public.cmserver.general/browse_thread/thread/29d63077144004a9/c3888efdcb7338f6?hl=en#c3888efdcb7338f6 About creating an Email...
0
by: amitp | last post by:
Can anyone help me out in this? I want to append multiple RTF file into one RTF file. I tried using 'streamwriter', the resulting file size becomes big and when i open it, it is the original i.e the...
0
by: cybersurfer | last post by:
Hi I am having a problem with appending one image to another in C# using the ImageAdmin.ocx control. The Append function call requires that 5 arguments be passed. Append ( System.String source ,...
2
by: sarada purkait | last post by:
hii i have to write into a file from the start and then go on appending to it .. i tried using ( ios::out|ios::app) but by this the file keeps on appending every time i run the program and the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.