Tag: 重定向

代码块重定向输入输出

我是代码块的新手,我似乎无法使用输出的命令行参数。 有谁知道怎么做? 我现在能够读取从argv [1]传递的文件但是,程序不会自动读取给定文件的输入,也不会将输出正确输出到文件输出。 我知道它是在set程序的参数上,我的参数行是:list.txt output 经过一些研究,我看到一个人这样做: ./output,好像在运行一个程序给出输入和输出,无论如何,我也尝试过无济于事。 我是否需要使用文件处理程序与之交互? 它没有成功,简单的getchar()应该从传递的输入文件中读取。 我在这里想念的是什么? 提前致谢

我怎么能临时将stdout重定向到C程序中的文件?

在我的C程序中,我想暂时将STDOUT重定向到“/ dev / null”(例如)。 然后写入“/ dev / null”之后我想恢复STDOUT。 我该如何管理?

Classic C.在execvp函数,stdin和stdout重定向中使用管道

我想使用管道和execvp函数在我的Linux C程序中模拟bash。 例如 ls -l | wc -l 有我的计划: if(pipe(des_p) == -1) {perror(“Failed to create pipe”);} if(fork() == 0) { //first fork close(1); //closing stdout dup(des_p[1]); //replacing stdout with pipe write close(des_p[0]); //closing pipe read close(des_p[1]); //closing pipe write if(execvp(bash_args[0], bash_args)) // contains ls -l /* error checking */ } else { if(fork() == 0) […]