#include #include void runCommand(char * command) { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&pi, sizeof(pi)); ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); printf("\nCommand: %s\n", command); CreateProcessA(NULL, command, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi); WaitForSingleObject(pi.hProcess, INFINITE); CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); fflush( stdout ); // insufficient when main() is called from Cygwin bash; added setbuf() fflush( stderr ); // } // [ "\\a\b" "c\\d" "\e\f" "\\\\g\\h" "QUOTED WORDS" WO\"RD \\a\b \\"a\b" \\a\"b \\\\"a \\\\\" b" ] // [ "\\a\b" "c\\d" "\e\f" "\\\\g\\h" "QUOTED WORDS" WO\"RD x" \\a\b \\"a\b" \\a\"b x" \\\\"a \\\\\" b" ] // The second line compensates Cygwin's interpretation of a bare (unquoted) // backslash followed by a double quote as two separate characters. #define COMMAND_ARGS " \"\\\\a\\b\" \"c\\\\d\" \"\\e\\f\" \"\\\\\\\\g\\\\h\" \"QUOTED WORDS\" WO\\\"RD" \ " \\\\a\\b \\\\\"a\\b\" \\\\a\\\"b" \ " \\\\\\\\\"a \\\\\\\\\\\" b\" " #define COMMAND_ARGS_CYGWIN_BARE_BACKSLASH_QUOTE " \"\\\\a\\b\" \"c\\\\d\" \"\\e\\f\" \"\\\\\\\\g\\\\h\" \"QUOTED WORDS\" WO\\\"RD x\"" \ " \\\\a\\b \\\\\"a\\b\" \\\\a\\\"b x\"" \ " \\\\\\\\\"a \\\\\\\\\\\" b\" " int main() { setbuf( stdout, NULL ); // just flushing these files appears to be insufficient setbuf( stderr, NULL ); // runCommand(".\\dumpargs_gcc.exe " COMMAND_ARGS_CYGWIN_BARE_BACKSLASH_QUOTE); runCommand(".\\dumpargs_cl.exe " COMMAND_ARGS); return 0; }