【问题标题】:Wait for the system() call to complete等待 system() 调用完成
【发布时间】:2013-03-01 14:59:15
【问题描述】:

在下面的代码中,我用"gedit filename" 调用system。它正在使用指定的文件正确打开 gedit
但是,在下一行中,我尝试打印修改后的数据(我将通过gedit 更新),但它不会等到gedit 退出。

strcpy(tt1,"gedit ");
strcat(tt1,tt);
system(tt1);                     //here gedit opens file

printf("\nFile data %s  Location %s",getFileData(tt),tt); //this line executes before finishing gedit

请帮我等到system() 调用完成。

【问题讨论】:

  • tt 包含什么?
  • gedit 可能像守护进程一样进入后台,许多 gui 程序都这样做。
  • tt 包含将用于 gedit 的文件名,例如gedit abc.txt 这里tt是abc.txt
  • 从shell调用gedit filename时,退出gedit前shell提示符是否返回?
  • 没有办法做到这一点..???

标签: c multithreading system wait


【解决方案1】:

我相信这是由--wait 命令行参数处理的,这似乎是一个漂亮的recent addition。您可以尝试自己构建 gedit,至少验证它是否有效(因为您的发行版可能没有足够新的构建版本)。

【讨论】:

  • 嘿嘿...谢谢 unwind ....它工作并解决了问题...谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢 unwind..
猜你喜欢
  • 2019-11-19
  • 1970-01-01
  • 2015-08-17
  • 2012-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-09
相关资源
最近更新 更多