Рабочий пример на Linux. замените / bin / bash на свое собственное местоположение bash
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <assert.h>
#include <sys/wait.h>
int plumbing( const char * work, char * results, size_t so_results) {
int p1[2],p2[2];
pid_t pid,pidw;
void (*old)(int);
int bytes,cnt,status,rc;
char * bash[2] = {"/bin/bash",0};
old=signal(SIGCHLD,SIG_DFL);
rc = pipe(p1); if(rc){perror("pipe()");return -1;}
rc = pipe(p2); if(rc){perror("pipe()");return -1;}
pid = fork();
if (pid<0) { perror("fork"); return -1;}
if (0 == pid) {
rc = dup2(p1[0],0); if (-1 == rc) {perror("dup2"); return -1;}
rc = dup2(p2[1],1); if (-1 == rc) {perror("dup2"); return -1;}
close(p1[1]); close(p2[0]);
rc = execvp(bash[0],bash);
if (-1 == rc) {perror("execvp"); return -1;} exit(-1);
}
close(p1[0]);close(p2[1]);
write(p1[1],work,strlen(work));
cnt = 0;
close(p1[1]);
bytes = read(p2[0],results,so_results);
while(bytes > 0) {
cnt+=bytes;
if (so_results== cnt) break;
bytes = read(p2[0],results+cnt,so_results-cnt);
}
if (cnt == so_results) {
char dummy[4096];
bytes = read(p2[0],dummy,4096);
while (bytes>0) {
bytes = read(p2[0],dummy,4096);
}
}
pidw = waitpid(pid,&status,WCONTINUED|WUNTRACED);
if (pidw != pid || status !=0 ) { perror("waitpid"); return -1;}
signal(SIGCHLD,old);
return 0;
}
int main() {
int rc;
char buffer[4096];
rc = plumbing(
"t=$(cat<< @@@\n"
"ICAgICAgIGE4ODg4Yi4KICAgICAgZDg4ODg4OGIuCiAgICAgIDhQIllQIlk4OAogICAgICA4fG98fG98\n"
"ODgKICAgICAgOCcgICAgLjg4CiAgICAgIDhgLl8uJyBZOC4KICAgICBkLyAgICAgIGA4Yi4KICAgIGRQ\n"
"ICAgLiAgICBZOGIuCiAgIGQ4OicgICIgIGA6Ojg4YgogIGQ4IiAgICAgICAgICdZODhiCiA6OFAgICAg\n"
"JyAgICAgIDo4ODgKICA4YS4gICA6ICAgICBfYTg4UAouXy8iWWFhXzogICAufCA4OFB8ClwgICAgWVAi\n"
"ICAgIGB8IDhQICBgLgovICAgICBcLl9fXy5kfCAgICAuJwpgLS0uLl9fKTg4ODhQYC5fLicK\n"
"@@@)\n"
"r64=\'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\'\n"
"i=0; while [ $i -lt 256 ] ; do tab[$i]=-1 ; let i=$i+1 ;done\n"
"i=0; while [ $i -lt 64 ] ; do tab[`printf \"%d\" \"\'${r64:$i:1}\"`]=$i ; let i=$i+1; done\n"
"bi=0\n"
"i=0 \n"
"while ((i < ${#t} )) \n"
" do\n"
" x=${t:$i:1}\n"
" in=${tab[`printf \"%d\" \"\'$x\"`]}\n"
" if [ $in -ge 0 ]; then case $bi in\n"
" 0 ) out=$(($in<<2)); bi=6 ;;\n"
" 2 ) out=$(($out|$in)); printf \\\\$(printf \'%03o\' $(($out&255)) ); bi=0 ;;\n"
" 4 ) out=$(($out+($in>>2))); printf \\\\$(printf \'%03o\' $(($out&255)) );\n"
" bi=0; out=$(($in<<6)); bi=2 ;;\n"
" * ) out=$(($out+($in>>4))); printf \\\\$(printf \'%03o\' $(($out&255)) );\n"
" bi=0; out=$(($in<<4)); bi=4 ;;\n"
" esac fi\n"
" i=$((1+$i))\n"
" done\n"
,buffer,4096);
printf("plumbing rc %d\n",rc);
printf("%s", buffer);
}