Aditi Garg Sharma
Aditi Garg Sharma

Reputation: 39

Implementing terminal commands with c

I have to write the c program that executes terminal commands which are in this order :

  1. cd ../../etc

  2. chmod a+x file

  3. cd alice/password

  4. more password

so if I have attack.c then by ./attack, all these should be implemented on the terminal. I tried using execvp() but its just not happening.

Upvotes: 0

Views: 7032

Answers (1)

shirish
shirish

Reputation: 678

You can run shell commands in C using the system() command (works in linux)

#include <stdio.h>
#include <stdlib.h>
int main() {
  system("cd ../../etc; chmod a + x file; cd alice/password; cat password");
  return 0;
}

Upvotes: 4

Related Questions