Calling unix commands in C++
Is it possible to call commands like 'cp' or 'mkdir' inside C++?
What I want to do is write a small program that will update my gentoo server. I know I could write this as a simple shell script but I would really like to get practice using C++. I am thinking once the program is done I can compile it and set it up in cron to update my server every month or so...
Any ideas or direction for me?
Thanks all,
Grey
system() should work
Here
Remember to
#include <cstdlib>
instead of
#include <stdlib.h>
But these kind of things are really better done with another language, like perl or /bin/sh .
Here
Remember to
#include <cstdlib>
instead of
#include <stdlib.h>
But these kind of things are really better done with another language, like perl or /bin/sh .
Since you want to do it in C rather than going through the shell, you'll want to use appropriate system calls rather than calling system()
mkdir() in <sys/stat.h>
To copy a file, you can either use link() in <unistd.h> to add a link to the file or copy the file "by hand" by creating a new file and copying the data into it.
mkdir() in <sys/stat.h>
To copy a file, you can either use link() in <unistd.h> to add a link to the file or copy the file "by hand" by creating a new file and copying the data into it.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement