我试图用另一个管道替换stdin,然后将原始stdin放回到fd#0.
例如
dup2(p, 0); // p is a pre-existing fd of a pipe
exec(/* some commands */);
//what will be here in order to have the original stdin back?
scanf(...) //continue processing with original stdin.
Run Code Online (Sandbox Code Playgroud)