感謝,你的資訊可以解決我的問題唷!
引用:
#include <stdio.h>
#include <unistd.h>
int main()
{
FILE *fp;
int ret;
int id,fd;
fp=fopen("/home/user/00.txt","w");
id = dup(STDOUT_FILENO);
fd=fileno(fp);
dup2(fd, STDOUT_FILENO);
ret = execl ("/bin/ls", "ls", "-1", (char *)0);
dup2(id, STDOUT_FILENO);
fclose(fp);
return 0;
}