ohnx / minervabot

Modular IRC bot. The reincarnation of athenabot!
Apache License 2.0
2 stars 1 forks source link

exec() command #10

Open ohnx opened 5 years ago

ohnx commented 5 years ago

Simple command to execute a command in the system. Only accessible to owner.

e.g.

https://stackoverflow.com/questions/646241/c-run-a-system-command-and-get-output

FILE *fp;
  char path[1035];

  /* Open the command for reading. */
  fp = popen("/bin/ls /etc/", "r");
  if (fp == NULL) {
    printf("Failed to run command\n" );
    exit(1);
  }

  /* Read the output a line at a time - output it. */
  while (fgets(path, sizeof(path)-1, fp) != NULL) {
    printf("%s", path);
  }

  /* close */
  pclose(fp);