public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: Incomplete environ when running MinGW apps?
@ 2008-07-15  8:27 Pedro Izecksohn
  2008-07-15 13:48 ` Christopher Faylor
  0 siblings, 1 reply; 15+ messages in thread
From: Pedro Izecksohn @ 2008-07-15  8:27 UTC (permalink / raw)
  To: cygwin

Reference: http://sourceware.org/ml/cygwin/2008-02/msg00181.html

"Are you sure SHELL was exported to the environment, and not just in the bash shell variable namespace?"

It is a documentation problem, from man bash:

"SHELL The full pathname to the shell is kept in this environment variable."

It may also be read from:
http://www.gnu.org/software/bash/manual/bashref.html

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Incomplete environ when running MinGW apps?
  2008-07-15  8:27 Incomplete environ when running MinGW apps? Pedro Izecksohn
@ 2008-07-15 13:48 ` Christopher Faylor
  2008-07-15 14:27   ` Markus Hoenicka
  0 siblings, 1 reply; 15+ messages in thread
From: Christopher Faylor @ 2008-07-15 13:48 UTC (permalink / raw)
  To: cygwin

On Tue, Jul 15, 2008 at 01:27:18AM -0700, Pedro Izecksohn wrote:
>Reference: http://sourceware.org/ml/cygwin/2008-02/msg00181.html
>
>"Are you sure SHELL was exported to the environment, and not just in the bash shell variable namespace?"
>
>It is a documentation problem, from man bash:
>
>"SHELL The full pathname to the shell is kept in this environment variable."
>
>It may also be read from:
>http://www.gnu.org/software/bash/manual/bashref.html

Why are you responding to this email 5+ months after it was sent?

cgf

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Incomplete environ when running MinGW apps?
  2008-07-15 13:48 ` Christopher Faylor
@ 2008-07-15 14:27   ` Markus Hoenicka
  0 siblings, 0 replies; 15+ messages in thread
From: Markus Hoenicka @ 2008-07-15 14:27 UTC (permalink / raw)
  To: cygwin

Quoting Christopher Faylor <cgf-use-the-mailinglist-please@cygwin.com>:

> Why are you responding to this email 5+ months after it was sent?
>

Distraction by incoming mails has been recognized as the main reason  
for low output by programmers. The cure is to switch to batch mode in  
email processing, like once in 5 months or so.

regards,
Markus

-- 
Markus Hoenicka
markus.hoenicka@cats.de
(Spam-protected email: replace the quadrupeds with "mhoenicka")
http://www.mhoenicka.de


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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Incomplete environ when running MinGW apps?
@ 2008-07-15 14:26 Pedro Izecksohn
  0 siblings, 0 replies; 15+ messages in thread
From: Pedro Izecksohn @ 2008-07-15 14:26 UTC (permalink / raw)
  To: cygwin

> From: Christopher Faylor
>> I wrote:
>> Reference: http://sourceware.org/ml/cygwin/2008-02/msg00181.html
>> ...
>> 
>> "SHELL The full pathname to the shell is kept in this environment variable."
>>
>> It may also be read from:
>>http://www.gnu.org/software/bash/manual/bashref.html
> 
> Why are you responding to this email 5+ months after it was sent?

  Because I found this in the documentation just now; and I hope that someone fix something.

  I lament this feature is not POSIX.

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Incomplete environ when running MinGW apps?
  2008-02-07 20:23           ` Dave Korn
@ 2008-02-08  3:52             ` Paul Leder
  0 siblings, 0 replies; 15+ messages in thread
From: Paul Leder @ 2008-02-08  3:52 UTC (permalink / raw)
  To: cygwin

Dave Korn wrote:

>   Out of curiosity, what's the problem with just using popen("...") always?

I get the feeling you're working up to telling me something I don't want 
to hear, but I shall carry on regardless... :)

[_]popen is fine if you want to execute a process and either just get 
its stdout, or just supply its stdin, but not both (and you only want a 
console app; it's buggy, apparently). If you want all 3 of stin, stdout, 
and stderr redirected, as I do, you must (I think) use CreateProcess and 
do the donkey work yourself. I haven't investigated what _popen does to 
slashes and quotes, but it's presumably the same as 'system'.

You only need to use pipes at all because Windoze processes can't 
reliably inherit sockets. But, as it turns out, the process and pipe 
creation is not the difficult part of the problem anyway. The real 
bu**er is connecting the pipes to the socket that talks to the remote 
peer. Since select is broken, you have to do this with multiple threads 
and events, and async waits.

-Paul

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* RE: Incomplete environ when running MinGW apps?
  2008-02-07 20:03         ` Paul Leder
@ 2008-02-07 20:23           ` Dave Korn
  2008-02-08  3:52             ` Paul Leder
  0 siblings, 1 reply; 15+ messages in thread
From: Dave Korn @ 2008-02-07 20:23 UTC (permalink / raw)
  To: cygwin

On 07 February 2008 18:25, Paul Leder wrote:

> Dave Korn wrote:
> 
>>   Out of curiosity, what's the problem with just using system("...")
>> always? 
> 
> I can't, because I need to redirect child I/O onto a socket, which
> requires CreateProcess. The Unix code is (relatively) easy, but it's a
> complete nightmare in Windoze. You have to use pipes as well as sockets,
> it has to be multi-threaded, select doesn't work, and so on.
> 
> I can use 'system' occasionally, but then I have the issues of
> forward/backslashes, extra backslashes, quotes, and so on. I haven't
> really got to the bottom of this. With CreateProcess I at least have the
> option to use /bin/sh, if it exists, which makes life a little easier
> (particularly for quote characters).

  Out of curiosity, what's the problem with just using popen("...") always?

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Incomplete environ when running MinGW apps?
  2008-02-07 18:14       ` Dave Korn
@ 2008-02-07 20:03         ` Paul Leder
  2008-02-07 20:23           ` Dave Korn
  0 siblings, 1 reply; 15+ messages in thread
From: Paul Leder @ 2008-02-07 20:03 UTC (permalink / raw)
  To: cygwin

Dave Korn wrote:

>   Out of curiosity, what's the problem with just using system("...") always?

I can't, because I need to redirect child I/O onto a socket, which 
requires CreateProcess. The Unix code is (relatively) easy, but it's a 
complete nightmare in Windoze. You have to use pipes as well as sockets, 
it has to be multi-threaded, select doesn't work, and so on.

I can use 'system' occasionally, but then I have the issues of 
forward/backslashes, extra backslashes, quotes, and so on. I haven't 
really got to the bottom of this. With CreateProcess I at least have the 
option to use /bin/sh, if it exists, which makes life a little easier 
(particularly for quote characters).

-Paul

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* RE: Incomplete environ when running MinGW apps?
  2008-02-07 18:04     ` Paul Leder
@ 2008-02-07 18:14       ` Dave Korn
  2008-02-07 20:03         ` Paul Leder
  0 siblings, 1 reply; 15+ messages in thread
From: Dave Korn @ 2008-02-07 18:14 UTC (permalink / raw)
  To: cygwin

On 07 February 2008 17:51, Paul Leder wrote:

> Hmm. I think you're right; I need to give up looking for a robust way to
> do this. I think I'll:
> 
> if(
>     (system(uname) looks sane) &&
>     (system(cygpath -m /bin/sh) returns success))
>       use CreateProcess with /bin/sh path returned by cygpath;
>   else
>       use CreateProcess with cmd.exe /c
> 
> And I'll need to test it when run from a DOS box, with Cygwin's bin in
> the path.

  Out of curiosity, what's the problem with just using system("...") always?

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Incomplete environ when running MinGW apps?
  2008-02-07 17:52   ` Greg Chicares
@ 2008-02-07 18:04     ` Paul Leder
  2008-02-07 18:14       ` Dave Korn
  0 siblings, 1 reply; 15+ messages in thread
From: Paul Leder @ 2008-02-07 18:04 UTC (permalink / raw)
  To: cygwin

Hmm. I think you're right; I need to give up looking for a robust way to 
do this. I think I'll:

if(
    (system(uname) looks sane) &&
    (system(cygpath -m /bin/sh) returns success))
      use CreateProcess with /bin/sh path returned by cygpath;
  else
      use CreateProcess with cmd.exe /c

And I'll need to test it when run from a DOS box, with Cygwin's bin in 
the path.

That should keep most of the people happy most of the time. Who can ask 
for more from Windows?  :)

Thanks

-Paul

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Incomplete environ when running MinGW apps?
  2008-02-07 17:08 ` Paul Leder
@ 2008-02-07 17:52   ` Greg Chicares
  2008-02-07 18:04     ` Paul Leder
  0 siblings, 1 reply; 15+ messages in thread
From: Greg Chicares @ 2008-02-07 17:52 UTC (permalink / raw)
  To: cygwin

On 2008-02-07 16:28Z, Paul Leder wrote:
> 
> [...] I've written an app which runs on Linux and 
> "Windows". Most of the time on "Windows", it's probably going to be 
> running on Cygwin/bash. However, there's always going to be someone who 
> runs it in a DOS box.
> 
> So, my problem is, how do I find out if they've got a sane shell or not? 
> I can't ask them to export SHELL; I might as well just ask them to 
> provide a command-line arg to tell me what their shell is anyway. I need 
> some automatic way to do it.

cat >what_shell.c <<\EOF
#include <stdio.h>
#include <stdlib.h>

int main()
{
  int z;
  z = system("uname");
  printf("%d\n", z);
  return z;
}
EOF

gcc -mno-cygwin -o what_shell.exe -W -Wall -pedantic -ansi what_shell.c

Cygwin bash output:

$ ./what_shell
CYGWIN_NT-5.1
0

CMD.EXE output:

C:\cygwin\tmp>what_shell
'uname' is not recognized as an internal or external command,
operable program or batch file.
1

Of course, that'll report a sane shell even in CMD.EXE if
Cygwin's /bin is on $PATH, but IIRC that might be what you
want: for example, it'll tell you whether you can run 'ls'
or have to fall back on 'dir'.

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Incomplete environ when running MinGW apps?
  2008-02-07 16:29 Phil Betts
@ 2008-02-07 17:08 ` Paul Leder
  2008-02-07 17:52   ` Greg Chicares
  0 siblings, 1 reply; 15+ messages in thread
From: Paul Leder @ 2008-02-07 17:08 UTC (permalink / raw)
  To: cygwin

Phil Betts wrote:

> Just export the variables you want.  That's the whole point of the
> export command.

They're not my variables. I've written an app which runs on Linux and 
"Windows". Most of the time on "Windows", it's probably going to be 
running on Cygwin/bash. However, there's always going to be someone who 
runs it in a DOS box.

So, my problem is, how do I find out if they've got a sane shell or not? 
I can't ask them to export SHELL; I might as well just ask them to 
provide a command-line arg to tell me what their shell is anyway. I need 
some automatic way to do it.

Thanks

-Paul

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* RE: Incomplete environ when running MinGW apps?
@ 2008-02-07 16:29 Phil Betts
  2008-02-07 17:08 ` Paul Leder
  0 siblings, 1 reply; 15+ messages in thread
From: Phil Betts @ 2008-02-07 16:29 UTC (permalink / raw)
  To: cygwin

Paul Leder wrote on Thursday, February 07, 2008 3:31 PM::

> Eric Blake wrote:
> 
>> Bash has two variable namespaces - shell variables, and environment
>> variables.  Are you sure SHELL was exported to the environment, and
>> not just in the bash shell variable namespace?
> 
> thanks - I had no idea there were 2 variable namespaces. It looks like
> everything I can see in 'environ' was explcitly exported in
> /etc/profile, or ~/.bashrc, or picked up from Windows.
> 
> Is there a way for C programs to pick up the contents of the shell
> variable namespace? In particular, is there some way I can pick up
> SHELL, or some other way that I can find out if my app's running on
> bash? 
> 
> Thanks
> 
> -Paul

Just export the variables you want.  That's the whole point of the
export command.

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Incomplete environ when running MinGW apps?
  2008-02-07 14:47 ` Eric Blake
@ 2008-02-07 16:16   ` Paul Leder
  0 siblings, 0 replies; 15+ messages in thread
From: Paul Leder @ 2008-02-07 16:16 UTC (permalink / raw)
  To: cygwin; +Cc: Eric Blake

Eric Blake wrote:

> Bash has two variable namespaces - shell variables, and environment
> variables.  Are you sure SHELL was exported to the environment, and not
> just in the bash shell variable namespace?

thanks - I had no idea there were 2 variable namespaces. It looks like 
everything I can see in 'environ' was explcitly exported in 
/etc/profile, or ~/.bashrc, or picked up from Windows.

Is there a way for C programs to pick up the contents of the shell 
variable namespace? In particular, is there some way I can pick up 
SHELL, or some other way that I can find out if my app's running on bash?

Thanks

-Paul

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Incomplete environ when running MinGW apps?
  2008-02-07 14:46 Paul Leder
@ 2008-02-07 14:47 ` Eric Blake
  2008-02-07 16:16   ` Paul Leder
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Blake @ 2008-02-07 14:47 UTC (permalink / raw)
  To: cygwin, sa212+mingw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Paul Leder on 2/7/2008 7:19 AM:
| Hi -
|
| I'm having a problem reading bash environment variables when running a
| MinGW app on Cygwin's bash. I'm trying this on the MinGW list as well,
| but no luck so far. The basic problem is that SHELL is not visible in
| environ (or from getenv) on the app, even thought the program was
| launched from bash, where SHELL has the value /bin/bash. Does that sound
| familiar to anyone?

Bash has two variable namespaces - shell variables, and environment
variables.  Are you sure SHELL was exported to the environment, and not
just in the bash shell variable namespace?

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
volunteer cygwin bash maintainer
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHqxfD84KuGfSFAYARAiJ1AKCEqdudB+9LZTYfsWJnnOXW16go8gCdFTOT
zmEpTVHV50jp8Pr6jY0KYys=
=fP1g
-----END PGP SIGNATURE-----

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Incomplete environ when running MinGW apps?
@ 2008-02-07 14:46 Paul Leder
  2008-02-07 14:47 ` Eric Blake
  0 siblings, 1 reply; 15+ messages in thread
From: Paul Leder @ 2008-02-07 14:46 UTC (permalink / raw)
  To: Cygwin

Hi -

I'm having a problem reading bash environment variables when running a 
MinGW app on Cygwin's bash. I'm trying this on the MinGW list as well, 
but no luck so far. The basic problem is that SHELL is not visible in 
environ (or from getenv) on the app, even thought the program was 
launched from bash, where SHELL has the value /bin/bash. Does that sound 
familiar to anyone?

I've done some simple experimenting, as follows. I've written a
small test prog that prints out the contents of MinGW's stdlib 
'environ'. This is what I'm seeing, running everything from a Cygwin 
bash shell:

$ environ_dump.exe > env1
$ sort env1 > env1s
$ wc env1s
    44 65 1464 env1s
$ set > env2
$ sort env2 > env2s
$ wc env2s
    74 104 2062 env2s

Comparing env1s and env2s, I see:

1 - various bash environment variables never made it as far as
'environ'. These include all the BASH* variables, OSTYPE, SHELL, and so on.

2 - Various single-quoted variables from env2s end up unquoted in 'environ'.

3 - various other minor changes.

At first sight, it appears that all the bash and cygwin-specific stuff
has been left out of environ, but a lot of it is still there -
CVS_RSH, HOME, and so on.

Presumably I'm doing something really dumb. Any ideas? This is a
more-or-less out-of-the-box Win2K machine which I use for testing.

Thanks

-Paul

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2008-07-15 14:27 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-15  8:27 Incomplete environ when running MinGW apps? Pedro Izecksohn
2008-07-15 13:48 ` Christopher Faylor
2008-07-15 14:27   ` Markus Hoenicka
  -- strict thread matches above, loose matches on Subject: below --
2008-07-15 14:26 Pedro Izecksohn
2008-02-07 16:29 Phil Betts
2008-02-07 17:08 ` Paul Leder
2008-02-07 17:52   ` Greg Chicares
2008-02-07 18:04     ` Paul Leder
2008-02-07 18:14       ` Dave Korn
2008-02-07 20:03         ` Paul Leder
2008-02-07 20:23           ` Dave Korn
2008-02-08  3:52             ` Paul Leder
2008-02-07 14:46 Paul Leder
2008-02-07 14:47 ` Eric Blake
2008-02-07 16:16   ` Paul Leder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).