C++打开具有 2 个约束的文件

C++ open a file with 2 constraints

本文关键字:约束 文件 C++      更新时间:2023-10-16

在 c++ 中,我想用记事本打开我的文本文件,但是:

  • 不要停止程序或等待关闭记事本...
  • 不创建控制台/cmd选项卡(我正在使用Visual Studio 2017,Windows(

可能吗?

我有这个: _popen("记事本.exe C:\X\X\X.txt", "R"(; 但它会打开一个 cmd 选项卡。

(仅限Windows的解决方案(

通过修改示例:https://learn.microsoft.com/en-us/windows/win32/procthread/creating-processes

对于C++:

#include <iostream>
#include <Windows.h>
int main(int argc, char* argv[])
{
if (argc != 2)
{
std::cout << "Usage: " << argv[0] << " [cmdline]n";
return EXIT_FAILURE;
}
STARTUPINFOA        si = {sizeof(si)};
PROCESS_INFORMATION pi = {};
// Start the child process.
if (!CreateProcessA(nullptr, // No module name (use command line)
argv[1], // Command line
nullptr, // Process handle not inheritable
nullptr, // Thread handle not inheritable
false,   // Set handle inheritance to FALSE
0,       // No creation flags
nullptr, // Use parent's environment block
nullptr, // Use parent's starting directory
&si,     // Pointer to STARTUPINFO structure
&pi))    // Pointer to PROCESS_INFORMATION structure
{
std::cout << "CreateProcess failed (" << GetLastError() << ").n";
return EXIT_FAILURE;
}
// Wait until child process exits.
//WaitForSingleObject(pi.hProcess, INFINITE);
// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return EXIT_SUCCESS;
}