简体   繁体   中英

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.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM