獲取子進程的退出碼“編程開發”
#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" <
#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 <