프로세스 실행 방법에 따라서 argument 해석이 어떻게 달라지는지 간단한 테스트를 수행했다.
테스트
프로세스를 실행시킬 수 있는 API중 ShellExecuteEx()와 CreateProcess() 에 대해서 테스트를 수행한다. 실행시 인자는 "12345"를 사용한다.
ShellExecuteEx
입력
| 인자 | 값 |
| SHELLEXECUTEINFO::lpFile | C:\Test\MyTest.exe |
| SHELLEXECUTEINFO::lpParameters | 12345 |
결과
| argument를 얻는 방법 | 결과 |
| CWinApp::m_lpCmdLine | 12345 |
| GetCommandLineW() | "C:\Test\MyTest.exe" 12345 |
| argc | 2 |
| argv[0] | C:\Test\MyTest.exe |
| argv[1] | 12345 |
CreateProcess 1
입력
| lpApplicationName | NULL |
| lpCommandLine | "C:\Test\MyTest.exe" 12345 |
결과
| argument를 얻는 방법 | 결과 |
| CWinApp::m_lpCmdLine | 12345 |
| GetCommandLineW() | "C:\Test\MyTest.exe" 12345 |
| argc | 2 |
| argv[0] | C:\Test\MyTest.exe |
| argv[1] | 12345 |
CreateProcess 2
입력
| lpApplicationName | C:\Test\MyTest.exe |
| lpCommandLine | "C:\Test\MyTest.exe" 12345 |
결과
| argument를 얻는 방법 | 결과 |
| CWinApp::m_lpCmdLine | 12345 |
| GetCommandLineW() | "C:\Test\MyTest.exe" 12345 |
| argc | 2 |
| argv[0] | C:\Test\MyTest.exe |
| argv[1] | 12345 |
CrateProcess 3
입력
| lpApplicationName | C:\Test\MyTest.exe |
| lpCommandLine | 12345 |
결과
| argument를 얻는 방법 | 결과 |
| CWinApp::m_lpCmdLine | |
| GetCommandLineW() | 12345 |
| argc | 1 |
| argv[0] | 12345 |
결론
- 프로세스를 실행할때는 가급적 ShellExecuteEx() API를 사용한다.
- CreateProcess() API를 사용할 때는 lpCommandLine 인자에 전체 명령행을 완성해서 전달한다.

