delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/07/04/02:25:10

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
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 <Takaaki DOT Ota AT am DOT sony DOT com>
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

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 <stdio.h>
#include <windows.h>

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 <stdio.h>
#include <windows.h>

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019