Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Date: Tue, 03 Jul 2001 23:24:48 -0700 (PDT) Message-Id: <20010703.232448.127867883.Takaaki.Ota@am.sony.com> To: cygwin AT cygwin DOT com Subject: Does crt prepare arg[cv]? From: Tak Ota X-Mailer: Mew version 1.95b126 on Emacs 21.0.103.1 / Mule 5.0 (SAKAKI) X-Telephone: +1-858-942-3239 X-Fax------: +1-858-942-9142 X-SnailMail: 16450 West Bernardo Drive MZ7205, San Diego, CA 92127-1804 Organization: Sony Electronics Inc. Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, While I was working on gdb modification I encountered a problem which answer must be in the source but I could not find it. Gdb is irrelevant to this question. The question is this. Is it CRT routines that parses the command line argument of CreateProcess and prepares argc, argv and envp? If the answer is yes I want to know how it parses the command line. The problem is when the following program "print_arg.c" is run from the program "create_process.c" the result argument is not what I expect. Running print_arg from bash manually results this. bash-2.05$ print_arg 'a '\''b c'\''' args = [d:\ota\project\hellogcc\print_arg.exe "a 'b c'"] argc = 2 argv[0] = print_arg argv[1] = a 'b c' Running create_process results this. bash-2.05$ create_process args = [.\print_arg.exe 'a '\''b c'\'''] CreateProcess success args = [.\print_arg.exe 'a '\''b c'\'''] argc = 3 argv[0] = ./print_arg argv[1] = a b argv[2] = c' I am puzzled. Could anyone help me solve this mystery? -Tak -------------------------- print_arg.c ------------------------------ #include #include int main(int argc, char **argv) { int i; fprintf(stderr, "args = [%s]\n", GetCommandLineA ()); fprintf(stderr, "argc = %d\n", argc); for(i = 0; i < argc; i++) { fprintf(stderr, "argv[%d] = %s\n", i, argv[i]); } } -------------------------- print_arg.c ------------------------------ ------------------------ create_process.c --------------------------- #include #include int main(int argc, char **argv) { char *args = ".\\print_arg.exe 'a '\\''b c'\\'''"; DWORD flags = 0; STARTUPINFO si; PROCESS_INFORMATION pi; memset (&si, 0, sizeof (si)); si.cb = sizeof (si); fprintf(stderr, "args = [%s]\n", args); if(CreateProcess(0, args, /* command line */ NULL, /* security */ NULL, /* thread */ TRUE, /* inherit handles */ flags, /* start flags */ NULL, /* env */ NULL, /* current directory */ &si, &pi)) { fprintf(stderr, "CreateProcess success\n"); WaitForSingleObject(pi.hProcess, INFINITE); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } else { fprintf(stderr, "error: %d\n", GetLastError()); } return 0; } ------------------------ create_process.c --------------------------- -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/