Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* executes a command and returns result */
- char* doCommand(char* cmd) {
- FILE* pipe = popen(cmd, "r");
- if (!pipe) {
- printf("Error opening pipe ");
- return "ERROR";
- }
- //fflush(stdout);
- char buffer[128];
- char* result;
- int started = 0;
- char* hold;
- while(fgets(buffer, 128, pipe) != NULL) {
- if (started != 0) {
- hold = mallocCat(result,buffer);
- free(result);
- result = hold;
- }else{
- result = malloc(sizeof(buffer));
- strcpy(result,buffer);
- started = 1;
- }
- }
- if (pclose(pipe) == -256) {
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement