0

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.

  • "that implements" do you want to say "that executes"? – Swordfish Oct 14 '18 at 10:39
  • Possible duplicate of [How do I execute a Shell built-in command with a C function?](https://stackoverflow.com/questions/19209141/how-do-i-execute-a-shell-built-in-command-with-a-c-function) – user202729 Oct 14 '18 at 10:39
  • Question is kind of similar but the solution is not working.I just want like a conversion of these four commands – Aditi Garg Sharma Oct 14 '18 at 10:43

1 Answers1

4

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;
}
shirish
  • 668
  • 4
  • 9