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
|
char RunShellExecuteA(const char a_cmd[], const char a_path[])
{
if (_access(a_path, 0) == -1)
{
printf("\n*********Error*********\n");
printf("경로명을 확인하세요.\n");
printf("***********************\n");
return 0;
}
// 실행을 위해 구조체 세트
SHELLEXECUTEINFOA info;
ZeroMemory(&info, sizeof(info));
info.cbSize = sizeof(info);
info.hwnd = NULL;
info.lpVerb = "open";
info.lpFile = "cmd";
info.lpParameters = a_cmd; // 명령어 ex) >> "/C mkdir .\\classes"
info.lpDirectory = a_path;
info.fMask = SEE_MASK_NOCLOSEPROCESS;
info.nShow = SW_HIDE;
// 프로그램을 실행한다.
int r = (int)ShellExecuteExA(&info);
int err_code = GetLastError();
if (err_code != 0) {
printf("\n*********Error*********\n");
printf("Error Code >> %x(%d)\n", err_code, err_code);
printf("***********************\n");
return 0;
}
if (info.hProcess != NULL)
{
//프로세스가 종료될 때까지 무한정 기다림
WaitForSingleObject(info.hProcess, INFINITE);
}
return 1;
}
|
cs |
참고
[MFC]외부 프로세스 종료까지 대기 (ShellExcute )
보통 ShellExcute() 함수를 이용해 외부 프로세스를 실행시키곤 합니다. 이때 외부 프로세스가 종료될때 까지 대기 해야 하는 경우가 있는데 이런 경우 사용할 수 있는 두 가지 코드를 설명하겠습니
lwj789.tistory.com
'C > C언어 코드 기록' 카테고리의 다른 글
다양한 문자열 형식간 형변환 (0) | 2022.09.28 |
---|---|
콘솔창 작업 표시줄 없애기 (0) | 2022.07.15 |
메모장에 글쓰기 (0) | 2022.06.24 |
C언어 파일 입출력 (텍스트 파일 생성) (0) | 2022.03.15 |
sprintf()함수 가변적으로 사용하기. (0) | 2021.12.23 |