C++系统函数挂起应用程序

标签 c++ process

我有以下代码

void reportResults() 
  {
    wstring env(_wgetenv(L"ProgramFiles"));
    env += L"\Internet Explorer\iexplore.exe";
    wstringstream url;
    url << "\"\"" << env.c_str() << "\"  <a href="http://yahoo.com" rel="noreferrer noopener nofollow">http://yahoo.com</a>\"";
    wchar_t arg[BUFSIZE];
    url.get(arg, BUFSIZE);
    wcout << arg << endl;
    _wsystem(arg);
  }

其中 arg 是: ""C:\Program Files\Internet Explorer\iexplore.exe"http://yahoo.com "

程序按预期运行,启动 IE 并导航到 Yahoo,但调用函数 (reportResults) 从未退出。如何让程序退出并使浏览器保持事件状态? 谢谢。

最佳答案

您想使用 _wspawn() 而不是 _wsystem()。这将为浏览器进程生成一个新进程。 _wsystem() 阻塞您创建的命令;这就是为什么您不返回代码的原因。 _wspawn() 创建一个新的独立进程,该进程应立即返回您的代码。

关于C++系统函数挂起应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/987585/

相关文章:

c++ - 当我定义一个指向类的指针时,错误 :expected constructor, 析构函数,或者在 '*' token 发生之前进行类型转换

c - 在不覆盖指针指向的值的情况下取消 C 中结构数组的索引

windows - OllyDbg 不能在 Windows 7 x64 上运行

C++ Windows - 如何从其 PID 获取进程路径(错误)

c++ - 矩形碰撞检测

c++ - 需要沙盒应用程序,该应用程序从在线不受信任的来源编译 C++ 模块

c++ - 线程和简单的死锁修复

c++ - C++ 中的正则表达式跳过

process - 将 WinDbg 附加到进程

ubuntu - 如何杀死在 Windows、Linux 和 MacOS 中特定端口上运行的进程 - C# (.Net Core)