Skip to content

Instantly share code, notes, and snippets.

@NeilHanlon
Created March 27, 2018 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NeilHanlon/5ad1716b9da3a79acbdc4910bae3f58f to your computer and use it in GitHub Desktop.
Save NeilHanlon/5ad1716b9da3a79acbdc4910bae3f58f to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char *argv[] ) {
FILE *fp;
char path[80];
fp = popen("/usr/bin/which telinit", "r");
if (fp == NULL) {
printf("Failed to run command\n");
exit(1);
}
while ( fgets(path, sizeof(path), fp) != 0) {
}
pclose(fp);
char cmd[100];
strcpy(cmd, "/bin/ls -la ");
strcat(cmd, path);
fp = popen(cmd, "r");
if (fp == NULL ) {
printf("Failed to run command\n");
exit(2);
}
char output[1035];
while (fgets(output, sizeof(output), fp)) {
printf("%s", output);
}
pclose(fp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment