Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. char* connections[10]; //each element contains user@host
  2. char cmdStr[50];
  3. //LOOP on each connections to copy so that cmdStr has
  4. cmdStr = "ssh -q connections[0] 'echo "hi"'"
  5. cmdStr = "ssh -q connections[1] 'echo "hi"'"
  6. etc. etc.
  7.  
  8. fp = popen(cmdStr,"r");
  9. if(fp!=NULL) //This always works even for for non existing user@host
  10. {
  11. //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
  12.  
  13. char line[3];
  14. if(fgets(line,sizeof(line),fp) != NULL) //SIGSEV here
  15. {
  16. printf("nReceived this a output from command = %sn",line);
  17. }
  18. else
  19. {
  20. printf("nERROR while reading the output from popen %sn",cmdStr);
  21. status = 1;
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement