delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2017/05/13/11:34:32

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:mime-version:in-reply-to:references:from:date
:message-id:subject:to:content-type; q=dns; s=default; b=jCkDCeS
DcxkLroZl4UKCGD2KOsS4EF8HHri0J/PTgOSE4KnN0fVINnFwDiGen/lZjNPofPX
Upm3z14SskNuwuow22xqxJv2L7VhhxJ/peselclJ6iTs0JqNXX8zdYfLkLdN5sSz
BaAFbOs4Z/CpVbx47vuIsmJkzCZGRJnF7GN0=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:mime-version:in-reply-to:references:from:date
:message-id:subject:to:content-type; s=default; bh=IiHgPWuddMkf8
BKO1MllzLKl7+o=; b=lZgIt6ZXGnt5zhsO3IanhTNc7ldpM3JZEEi+8yjqtVaIT
64iUoNsYcD2UCES8T3rOqNU7x+6HXNfZ7UPkTEszYDEewuCiHXSx4mgL+wRV5h4n
dkKiiD6zBO76H6xbFWIN2rWmT/qhimKyQRnXnRY5Dy8fMdOfraccpfsXsaZFRU=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=0.6 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=UD:test.exe, test.exe, testexe, barry
X-HELO: mail-pg0-f41.google.com
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to; bh=/m9NFZua4jS6baFyE/sN4QmdPNDS12OPC8ANKX6LfGg=; b=QE2xKdE0HCza0XmygjYrIfQDvU34Dh155lDHbnnxMnVqJag5h1AUYg4W+aQsyKkl2I pAX3a50CODiH859LPJQ26TRs5K0hKKVf7mpcw7i9eGZEXUVaEFgb9qlF6C739nlNQPsC 7W8NrDLBYL7eAJ8YfPi3qhFtuqLJgVgUfHpSTOELr8KXCgS5B9z7Zr9ZiBAyuNjnssSc j11IX3mEUPSta2r7+cZPVgBrLykC1Ntl0fZKH4Mut0z8PbY1kTxOxJMyQfLYwXCBfH3I yJBLd8Gr3tsAN9yM/MdsVjXgMNNOoGZ5K6k6JtI3R3A1VGrEYvCI7Qxc8xElotHyg57B rsvw==
X-Gm-Message-State: AODbwcCFLxUA3K22eNCHVbi53NTM2izaFr7hJRAbgWDDlItrR9JbOujQ p6OJm8ILXeqfF8PcmtiW5Uzl0rSanA==
X-Received: by 10.84.132.2 with SMTP id 2mr13476092ple.46.1494689654528; Sat, 13 May 2017 08:34:14 -0700 (PDT)
MIME-Version: 1.0
In-Reply-To: <CAF_6hF4+jNWuqA-7jSn2=Jqb2X--MDmY0qhbNwtLxBcHwkrxbA@mail.gmail.com>
References: <CAF_6hF4+jNWuqA-7jSn2=Jqb2X--MDmY0qhbNwtLxBcHwkrxbA AT mail DOT gmail DOT com>
From: Dan Kegel <dank AT kegel DOT com>
Date: Sat, 13 May 2017 08:34:14 -0700
Message-ID: <CAPF-yOa3R1ghm-rKOcjtMpFtQWXpJRi42x90ZJd1GBZ6HeBUSA@mail.gmail.com>
Subject: Re: BUG: winmain GetCommandLine only returning program name and path with no arguments
To: mikebarry AT gmail DOT com, cygwin AT cygwin DOT com
X-IsSubscribed: yes

That same executable behaves properly when built with cl.exe *or* run from cmd.

Only when built with cygwin gcc *and* run from cygwin shell does it
not show the full string,
and bonus, in that case does not set szCmdLine properly?

#include <windows.h>
#include <stdio.h>

int WINAPI
WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) {
        char* text = GetCommandLine();
        printf("getcmdline: %p %s\n", text, text);
        printf("szCmdLine: %p %s\n", szCmdLine, szCmdLine);
        return 0;
}

Built as a.exe by gcc, example.exe by cl

$ ./a.exe x y z
getcmdline: "C:\cygwin64\home\buildbot\a.exe"
szCmdLine:

$ ./example.exe x y z
getcmdline: C:\cygwin64\home\buildbot\example.exe x y z
szCmdLine: x y z

$ cmd
Microsoft Windows [Version 10.0.10240]
(c) 2015 Microsoft Corporation. All rights reserved.

C:\cygwin64\home\buildbot>a.exe x y z
getcmdline: a.exe  x y z
szCmdLine: x y z

C:\cygwin64\home\buildbot>example.exe x y z
example.exe x y z

C:\cygwin64\home\buildbot>getcmdline: example.exe  x y z
szCmdLine: x y z

(Incidentally,
http://stackoverflow.com/questions/13871617/winmain-and-main-in-c-extended/13872211
and
http://daviddeley.com/autohotkey/parameters/parameters.htm looks
like informative if one is interested in some nasty details. )

On Sat, May 13, 2017 at 7:30 AM, Mike Barry <mike DOT barry AT gmail DOT com> wrote:
> Below is a sample program that demonstrates that the GetCommandLine
> function is not returning the command line arguments.  I attached
> cygcheck.out.
>
> #include <windows.h>
> #include <stdio.h>
>
> int WINAPI
> WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) {
>         char* text = GetCommandLine();
>         printf("getcmdline: %s\n", text);
>         return 0;
> }
>
> gcc test_wmain.c -o test
>
> $ ./test hello world
> getcmdline: "C:\cygwin64\home\mbarry\game-repos\greenbeam\src\test.exe"
>
>
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


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