Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <errno.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <unistd.h>
- #include <string.h>
- int main(){
- int pipedes1[2],pipedes2[2];
- char buff[256];
- string text = "Hello";
- pid_t pid;
- pipe(pipedes1);
- pipe(pipedes2);
- pid = fork();
- if(pid > 0){
- close(pipedes1[1]);
- close(pipedes2[0]);
- dup2(pipedes2[1], STDOUT_FILENO);
- dup2(pipedes1[0], STDIN_FILENO);
- execve("/home/pi/Test", NULL, NULL);
- } else {
- close(pipedes1[1]);
- close(pipedes2[1]);
- write(pipedes1[0], text.c_str(), text.length());
- while((len = read(pipedes2[0], buff, 256)) != 0){
- cout << buff << endl;
- }
- close(pipedes2[0]);
- close(pipedes1[0]);
- }
- return 0;
- }
- int main(){
- string str;
- cin >> str;
- str = "echo " + str + " >> /home/pi/1";
- cout << str << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement