我正在使用popen打开一个写入管道并将命令发送到应用程序。问题是,只有在关闭管道时才会将命令发送给应用程序。使用popen在管道中写入时只能在管道关闭时发送数据
FILE * fp = open(target_app, "w");
fwrite(command, 1, command.size(), fp);
getchar(); //wait for a key, because I don't want to terminate the application
pclose(fp); // at this point, the command is sent
什么可能是错的?
我已经试过\ n,但它不会工作。我能做到的唯一方法就是使用fflush。 – carlfilips 2010-07-27 23:47:43
是的,因为这是做这件事的好方法:) – Shahor 2010-07-28 07:59:10