【问题标题】:How do I read the console output from a SHELLEXECUTEINFO object?如何从 SHELLEXECUTEINFO 对象读取控制台输出?
【发布时间】:2021-09-03 15:17:34
【问题描述】:

我正在使用 SHELLEXECUTEINFO 对象通过 Visual C++ 执行 C# 控制台应用程序。如何在 Visual C++ 应用程序中读取 C# 控制台应用程序的控制台输出?

到目前为止,这是我的工作代码:

SHELLEXECUTEINFO ShExecInfo = { 0 };
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "myapp.exe";        
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess, INFINITE);

【问题讨论】:

    标签: c++ winapi visual-c++


    【解决方案1】:

    使用ShellExecute/Ex() 时,您无法读取衍生进程的输出。您需要改用CreateProcess()。它有一个STARTF_USESTDHANDLES 标志,用于使用您提供的管道重定向衍生进程的STDIN/STDOUT/STDERR`。有关示例,请参阅 MSDN 上的 Creating a Child Process with Redirected Input and Output

    【讨论】:

      猜你喜欢
      • 2011-05-15
      • 1970-01-01
      • 2019-12-24
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多