Tak, chciałbym, żeby Potomek to wykonał. Teraz mój kod wygląda tak, i zamiast wykonania komendy dostaje napis "ls -la"
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
const size_t BufSize = 1024;
int main()
{
pid_t pid;
int fd[2];
char buffer[BufSize];
const char * cmd = "ls -la";
if(pipe(fd)<0)
printf("Cannot create pipe\n");
int pipe_result;
pipe_result =pipe(fd);
if (pipe_result<0)
printf("error");
pid= fork();
if(pid<0) {
printf("Couldn't create child process, err =%d\n", pid);
return -1;
} else if (pid ==0) {
close(fd[0]);
write(fd[1], cmd, strlen(cmd));
close(fd[1]);
} else
{
close(fd[1]);
size_t nread = read(fd[0], buffer, BufSize);
if (nread > 0)
{
for ( size_t n = 0; n < nread; ++n)
putchar( buffer[n] );
putchar('\n');
}
close(fd[0]);
}
return 0;
}