Thank you very much.
Another question:
Do you think it is a good practice to use shell command in .c, while
functions are available to do the same thing but in a more complicated
way? The only disadvantage of calling shell commands I can think of is
compromising the portablity of the program. What do you guys suggest?
Issues to consider with system()
1) how portable does you code need to be? If you are never going to
run your program on anything other than the system which you are
currently using, then *for you*, portability isn't an
issue. However, recognize that even between versions of the same
operating system shell commands can change their output
significantly, accept different flags, alter their behaviour for
the same flag, or simply become obsolete.
2) How does the shell command communicate errors? If the shell
command simply returns 0 on success and 1 on failure is that
sufficient?
3) If you are interested in more than just success/failure of the
command, how do you go about capturing the output of your command?
4) calling system imposes the overhead of statring up the command
processor, parsing the command line, executing the command, and
returning a value to the calling process. Is this overhead
acceptable to your current problem? Also, don't forget that the
system() call might fail because of resource problems.
5) assuming you can need to parse the output of your shell command and
know how to go achieve that, how difficult is is to write the
associated parser? If the command produces diagnostics as well as
'interesting' output, can you easily determine which is which?
Suppose that you've arranged for your stdout and stderr to be
written to different files, do you need to be able to determine
when the diagnostic was written in realation to the stdout? If so,
is *that* easy to do? Alternatively, you may have arranged for
your stdout and stderr to be interleaved, in which case you need to
be able to determine which line(s) are diagnostic and which are
not. Worse, you may have diagnostic and non-diagnostic output on
the same line.
6) there's always the tradeoff between the time needed to learn to use
a set of functions and getting something done "quick and dirty."
If your program is a one-shot deal, and you just need to test for
success/failure of the command then system() may be the way to go.
If your program is going into long term use, then the effort needed
to learn the function suite may be worth it, particularly if you
may need a program that needs similar functionality in the future.
Lastly, learning to use your system's library functions can only
improve your skills and knowlege of your system, and as a programmer,
isn't that your ultimate goal?