为什么exevp之前的printf无法运行? [英] Why is printf before exevp not running?
本文介绍了为什么exevp之前的printf无法运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到"hi!"的输出.为什么这还不打印东西"?
I get an output of "hi!". Why is this not also printing "something"?
#include <stdio.h>
#include <unistd.h>
int main(int argc, char** argv) {
char* program_name = "echo";
char* args[]= {program_name,"hi!",NULL};
printf("something");
execvp(program_name,args);
return 0;
}
我知道我不是先创建子进程.如果我取出execvp行,它会按预期工作.奇怪的. (注意:回声"是指 https://en.wikipedia.org/wiki/Echo_(命令))
I know I'm not creating a child process first. If I take out the execvp line, it works as expected. Weird. (Note: "echo" refers to https://en.wikipedia.org/wiki/Echo_(command))
推荐答案
该字符串位于io缓冲区中-因此请拉链并刷新该缓冲区
The string is in the io buffer - so pull the chain and flush that buffer
即添加
fflush(stdout)
在printf
之后(或将\n
添加到printf
)
这篇关于为什么exevp之前的printf无法运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文