Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

282
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda