Created
March 27, 2018 17:05
-
-
Save NeilHanlon/5ad1716b9da3a79acbdc4910bae3f58f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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