1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| HANDLE WriteHandle, ReadHandle ;
SECURITY_ATTRIBUTES SecAttr ;
SecAttr.nLength=sizeof(SECURITY_ATTRIBUTES);
SecAttr.bInheritHandle=TRUE;
SecAttr.lpSecurityDescriptor = NULL;
if (!CreatePipe(&ReadHandle, &WriteHandle, &SecAttr, 0)){
AfxMessageBox("erreur à la creation du pipe");
return;
}
if (!SetHandleInformation(ReadHandle, HANDLE_FLAG_INHERIT, 0)){
AfxMessageBox("erreur à la creation du handle");
return;
}
STARTUPINFO siStartupInfo;
PROCESS_INFORMATION piProcessInfo;
memset(&siStartupInfo, 0, sizeof(siStartupInfo));
memset(&piProcessInfo, 0, sizeof(piProcessInfo));
siStartupInfo.cb = sizeof(siStartupInfo);
siStartupInfo.dwFlags=STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
siStartupInfo.wShowWindow=SW_HIDE;
siStartupInfo.hStdOutput=WriteHandle;
/*if(CreateProcess(NULL,,0,0,FALSE,
CREATE_DEFAULT_ERROR_MODE,0,0,
&siStartupInfo,&piProcessInfo) == FALSE)
{
// erreur
}*/
if( !CreateProcess(NULL,
"plink.exe -ssh -l walk41 sfxz03 -pw wi ls", // command line
NULL, // process security attributes
NULL, // primary thread security attributes
TRUE, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartupInfo, // STARTUPINFO pointer
&piProcessInfo) // receives PROCESS_INFORMATION
){
AfxMessageBox("erreur d'exécution");
return;
}
WaitForSingleObject (piProcessInfo.hProcess, INFINITE);
CloseHandle (piProcessInfo.hProcess);
CloseHandle (piProcessInfo.hThread);
CloseHandle(WriteHandle);
DWORD dwRead, dwWritten;
CHAR chBuf[2048];
BOOL bSuccess = FALSE;
bSuccess = ReadFile(WriteHandle, chBuf, 2048, &dwRead, NULL);
AfxMessageBox(chBuf); |
Partager