473,224 Members | 1,306 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,224 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 3136
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.