获取子进程的退出码
2017-12-20 09:25
260 查看
#include "stdafx.h" #include "windows.h" #include "iostream" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { LPCTSTR lpName(_T("zzc")); LPCTSTR lpValue(_T("88888")); //设置环境变量的值 ::SetEnvironmentVariable(lpName,lpValue); STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); ZeroMemory(&pi, sizeof(pi)); if( !CreateProcess( _T("D:\\绘图编程\\父子进程通信-环境变量\\Child\\Debug\\Child.exe"), NULL, NULL, NULL, TRUE, CREATE_NEW_CONSOLE/*DETACHED_PROCESS*/,//新进程使用自己的可控制台窗口 NULL, NULL, &si, &pi) ) { cout <<"shibai" <<endl; } else{ cout << "chenggong" << endl; } //关闭子进程的主线程句柄,因为不在使用了 CloseHandle(pi.hThread); //子进程终止时,子进程句柄会变为已触发状态 WaitForSingleObject(pi.hProcess,INFINITE); //获取子进程的退出码 DWORD dwExitCode; GetExitCodeProcess(pi.hProcess,&dwExitCode); cout << "子进程的退出码:" << dwExitCode << endl; //关闭子进程句柄 CloseHandle(pi.hProcess); system("pause"); return 0; }
#include "stdafx.h" #include "windows.h" #include "iostream" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { LPCTSTR lpName(_T("zzc")); int nlength = ::GetEnvironmentVariable(lpName,NULL,0); LPTSTR lpValue = new TCHAR[nlength+1]; memset(lpValue,'\0',nlength+1); ::GetEnvironmentVariable(lpName,lpValue,nlength+1); setlocale(LC_ALL, "chs"); _tprintf(lpValue); cout <<lpValue<<endl; system("pause"); return 10; }
相关文章推荐
- Linux C 获取进程的退出值
- 父进程获取子进程退出状态(1)
- c# process 获取进程退出码
- bat处理中添加%errorlevel%在进程的后面获取进程退出码
- shell同时启多个进程,并等待所有子进程结束,再做接下来的操作,最好能获取每个子进程的退出状态
- 父进程获取子进程退出状态(2)
- Linux C 获取进程退出值的实现代码
- LINUX下获取所有进程信息
- C++ 获取进程内存占用和CPU利用率等信息
- java 获取进程的processId
- Android开发之获取系统所有进程信息。
- Android程序退出彻底关闭进程的方法
- ring0获取指定进程的PEB
- 退出xshell而进程不中断进程-screen命令
- 获取WPF窗体/控件的句柄/当前进程的句柄
- Windows Minifilter驱动 - 获取进程ID, 进程名字和线程ID (5)
- 用C#获取进程信息(转)
- Linux中获取某个进程的系统调用以及参数(故障排查案例)
- 随笔: linux系统中,获取进程运行时的环境变量
- 获取 / 修改进程资源限制