Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <errno.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <sys/types.h>
  6. #include <sys/wait.h>
  7. #include <unistd.h>
  8. #include <string.h>
  9.  
  10. int main(){
  11. int pipedes1[2],pipedes2[2];
  12. char buff[256];
  13. string text = "Hello";
  14. pid_t pid;
  15. pipe(pipedes1);
  16. pipe(pipedes2);
  17. pid = fork();
  18. if(pid > 0){
  19.  
  20. close(pipedes1[1]);
  21. close(pipedes2[0]);
  22.  
  23. dup2(pipedes2[1], STDOUT_FILENO);
  24. dup2(pipedes1[0], STDIN_FILENO);
  25.  
  26. execve("/home/pi/Test", NULL, NULL);
  27.  
  28. } else {
  29.  
  30. close(pipedes1[1]);
  31. close(pipedes2[1]);
  32.  
  33. write(pipedes1[0], text.c_str(), text.length());
  34. while((len = read(pipedes2[0], buff, 256)) != 0){
  35. cout << buff << endl;
  36. }
  37. close(pipedes2[0]);
  38. close(pipedes1[0]);
  39. }
  40. return 0;
  41. }
  42.  
  43. int main(){
  44. string str;
  45. cin >> str;
  46. str = "echo " + str + " >> /home/pi/1";
  47. cout << str << endl;
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement