Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char* connections[10]; //each element contains user@host
- char cmdStr[50];
- //LOOP on each connections to copy so that cmdStr has
- cmdStr = "ssh -q connections[0] 'echo "hi"'"
- cmdStr = "ssh -q connections[1] 'echo "hi"'"
- etc. etc.
- fp = popen(cmdStr,"r");
- if(fp!=NULL) //This always works even for for non existing user@host
- {
- //status = pclose(fp); //65280 is the return value from shell that means popen is succesful but command execution returned 65280. Hence checking the status is necessary before fgets otherwise it can result in SIGSEV. But if i pclose(fp), then fgets on fp wont be possible
- char line[3];
- if(fgets(line,sizeof(line),fp) != NULL) //SIGSEV here
- {
- printf("nReceived this a output from command = %sn",line);
- }
- else
- {
- printf("nERROR while reading the output from popen %sn",cmdStr);
- status = 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement