c++ - C ++打开具有2个约束的文件
问题描述
在 C++ 中,我想用记事本打开我的文本文件,但是:
- 不要停止程序或等待关闭记事本......
- 不创建控制台/cmd 选项卡(我正在使用 Visual Studio 2017,Windows)
可能吗 ?
我有这个: _popen("notepad.exe C:\X\X\X.txt", "r"); 但它会打开一个 cmd 选项卡。
解决方案
(仅限 Windows 的解决方案)
通过修改示例:https ://docs.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;
}
推荐阅读
- mysql - 在一个查询中更新具有不同值的多行
- rest - 在 JMeter 的 HTTP 请求采样器的正文部分中使用参数的语法,使用带有正文的 Rest API POST 请求和来自 CSV 文件的输入
- javascript - 传递 ReactElement 和返回 ReactElement 的函数之间的区别
- powershell - PowerShell 作业与启动进程
- html - 如何在一列中制作 3 个表格列?
- asp.net-mvc - 如何为动态角色实现用户管理 ASP.Net MVC
- c# - Unity c#脚本中的Trail Renderer
- python - 类属性的链表
- networking - 丢弃的大 UDP 多播消息
- javascript - JavaScript 调用类的默认值