hev CreatProcess 함수의 문제가 C++의 windows.h 헤더에 추가되었습니다. 나는 cmd 명령을 포함하는 TCHAR 변수를 전달하려고 할 때마다 오류를 반환합니다. CreateProcess failed (2). 이 설명과 해결책을 기다리고 있습니다.왜 명령이 CreateProcess와 함께 실행되지 않습니까?
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
int _tmain(int argc, TCHAR *argv[])
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
if(argc != 2)
{
printf("Usage: %s [cmdline]\n", argv[0]);
return 0;
}
// Start the child process.
if(!CreateProcess(NULL, // No module name (use command line)
argv[1], // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi) // Pointer to PROCESS_INFORMATION structure
)
{
printf("CreateProcess failed (%d).\n", GetLastError());
return 0;
}
// Wait until child process exits.
WaitForSingleObject(pi.hProcess, INFINITE);
// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
주의 : :
아래 코드를 고려 내가 "C : \ code.exe"> =처럼 잘 작동 가깝지만의 경로를 지정하여 응용 프로그램을 시작할 때
하는 경우 응용 프로그램이 작동하지? Code.exe C : \ Code.exe가 작동 중입니까? –
DOS 명령을 인수로 전달하는 경우 – afr0ck