我正在分离一个子进程,需要以反向数字顺序对几个char数组进行排序。我能够将数据传输到那里并且没有任何问题,但出于某种原因“排序”并没有对数据做任何事情。我确信我的错误很小,但我似乎无法把它搞定。有什么建议吗?
if (pid == 0){ // child process---------------------------------
close(pipe1[1]); // close write end of pipe1
close(pipe2[0]); // close read end of pipe2
dup2(pipe1[0], STDIN_FILENO);
dup2(pipe2[1], STDOUT_FILENO);
close(pipe1[0]); // close read end of pipe1
close(pipe2[1]); // close write end of pipe2
execlp("sort", "sort", "-nr", NULL); // sort incoming data
cout << "error" << endl; // if this line is reached, error
exit(0);
}