-
-
Save lazka/3d828f9ed3bdf6b981eeb5edca65c657 to your computer and use it in GitHub Desktop.
cygwin arg passing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <stdio.h> | |
int main(void) { | |
LPCWSTR applicationName = L"C:\\cygwin64\\bin\\echo.exe"; | |
LPWSTR commandLine = L"-- -FOO=\\\"BAR\\\""; | |
printf("# Using CommandLineToArgvW:\n"); | |
LPWSTR *arg_list; | |
int arg_count; | |
WCHAR fullCommandLine[MAX_PATH] = L""; | |
wcscat(fullCommandLine, applicationName); | |
wcscat(fullCommandLine, L" "); | |
wcscat(fullCommandLine, commandLine); | |
arg_list = CommandLineToArgvW(fullCommandLine, &arg_count); | |
for(int i=0; i<arg_count; i++) | |
printf("%d: %ws\n", i, arg_list[i]); | |
printf("# Using CreateProcessW and cygwin echo.exe:\n"); | |
BOOL ret; | |
PROCESS_INFORMATION pi; | |
STARTUPINFOW si; | |
si.cb = sizeof(si); | |
ZeroMemory(&si, sizeof(si)); | |
ZeroMemory(&pi, sizeof(pi)); | |
ret = CreateProcessW( | |
applicationName, commandLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using CommandLineToArgvW: | |
0: C:\cygwin64\bin\echo.exe | |
1: -- | |
2: -FOO="BAR" | |
# Using CreateProcessW and cygwin echo.exe: | |
-FOO=\BAR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment