I am really new to advanced programming (at least this is advanced for me)
I want to learn how to run shell commands through C program on windows
I did search for it and I know it has got something to do with system() and exec() but I didn't get a definite answer.
To begin with,i would like to execute cd command and also md command
So if someone can break this down to really basic level,it will be much appreciated. Thank you
P.S. I succeeded in doing so and I know now one shouldn't run system commands through C but this was just an assignment.Thank you
Here's a short program that runs dir from inside a C program.
#include <stdlib.h>
int main() {
system("dir");
return 0;
}
Basically, whatever command you pass as a string inside the parameter for system() is run using the shell on your system. In your case, since you are working on Windows, it is equivalent to running the string inside your command prompt. This is equivalent to the "DOS Commands" you talk about. However, these are actually shell commands.
Note: In general, you do NOT want to be running system() since there are almost always a better way of doing things. Also, if your code is just basically what is above, then you're better off writing a batch file (i.e. a .bat file).