Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

279
Views
How to run shell commands in a C program

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

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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).

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!