Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > system fucntion in C

Reply
Thread Tools

system fucntion in C

 
 
aki
Guest
Posts: n/a
 
      10-28-2010
Hi Guys ,

I want to use system function in C to do the following work.

cp <file1> <file2> and then ><file1>
e,g cp \var\log\cpm_cpmd_1.log.1 \var\log\cpm_cpmd_1.log.2 and then
>\var\log\cpm_cpmd_1.log.1


1. g_config_info.cpmm_config.cpm_log_path=\var\log\
2. p_g_log_limit_info[thread_id]->file_name= cpm_cpmd_1.log

system("cp (g_config_info.cpmm_config.cpm_log_path)+
(p_g_log_limit_info[thread_id]->file_name)
+'.'+'1' (g_config_info.cpmm_config.cpm_log_path)+
(p_g_log_limit_info[thread_id]->file_name)+'.'+'2'");


I am doing like this but it is not working . It seems the command
being executed is
cp \var\log\cpm_cpmd_1.log.1\var\log\cpm_cpmd_1.log.2

CAn anybody help .

regards
Akhielsh
 
Reply With Quote
 
 
 
 
Seebs
Guest
Posts: n/a
 
      10-28-2010
On 2010-10-28, aki <(E-Mail Removed)> wrote:
> I want to use system function in C to do the following work.


I would suggest that you consider the possibility that you are not yet
anywhere near ready to attempt this. I'll explain why.

> cp <file1> <file2> and then ><file1>


> e,g cp \var\log\cpm_cpmd_1.log.1 \var\log\cpm_cpmd_1.log.2 and then
> >\var\log\cpm_cpmd_1.log.1


Okay, right here:

There are no systems on which there is such a thing as /var/log which use
backslashes in paths.

If you're sufficiently careless about details to get that wrong, you
should NOT be writing code which will perform any sort of file operations!

> 1. g_config_info.cpmm_config.cpm_log_path=\var\log\
> 2. p_g_log_limit_info[thread_id]->file_name= cpm_cpmd_1.log


Again, it's not backslashes.

> system("cp (g_config_info.cpmm_config.cpm_log_path)+
> (p_g_log_limit_info[thread_id]->file_name)


Strings don't add in C.

> +'.'+'1' (g_config_info.cpmm_config.cpm_log_path)+
> (p_g_log_limit_info[thread_id]->file_name)+'.'+'2'");


If you want to use a language where stuff like this works, it's not
C.

> CAn anybody help .


I could, but I am concerned that if I give you any direction towards
what you're trying to do, you'll end up doing horrible damage.

.... But hey, not to *my* system.

So, here's what to do.

1. LEARN THE DIFFERENCE BETWEEN SLASH AND BACKSLASH. Now. Stop everything
else until you can get that right consistently and effortlessly. More
generally, if you don't immediately spot punctuation mismatches, you're
not in a good place to be working in C.
2. Understand that, in C, '.' is not a string, it's a character. Strings
and characters are different.
3. Usually, the right idiom for something like this is to use snprintf()
to populate a command buffer. (If you have a very old compiler, or a MS
compiler, it may lack snprintf(), in which case you might fall back on
sprintf(), but you'll be in significant danger of buffer overruns.)

Typically, the right way to do this is to figure out what your
command looks like in the abstract:
"cp <file1> <file2>"
then figure out how to convert it to a format string.

As to the ">file1", you shouldn't use system() for that, because you can
do it natively in C with less code.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: More Help with python .find fucntion Steven D'Aprano Python 0 01-08-2011 05:35 AM
Stopping a fucntion from printing its output on screen sophie_newbie Python 4 10-18-2007 08:00 AM
Random fucntion with a twist alphaLaura@gmail.com C++ 7 01-28-2007 06:46 PM
How can i return an iterator from a fucntion? TOMERDR C++ 6 05-22-2006 09:21 PM
Now() Fucntion and CurrentCulture ra294 ASP .Net 5 11-26-2004 08:51 AM



Advertisments