[issue37066] os.execl opening a new bash shell doesn't work if initfile/rcfile provided

2019-05-27 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37066] os.execl opening a new bash shell doesn't work if initfile/rcfile provided

2019-05-27 Thread Siming Yuan


Siming Yuan  added the comment:

thank you for the insight and quick response.

thought i hit the weirdest bug ever

--
resolution:  -> not a bug

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37066] os.execl opening a new bash shell doesn't work if initfile/rcfile provided

2019-05-27 Thread Anthony Sottile


Anthony Sottile  added the comment:

They're thin wrappers around the same C functions -- that's just how C works

it is also documented: https://docs.python.org/3/library/os.html#os.execvpe

> In either case, the arguments to the child process **should start with the 
> name of the command being run**, but this is not enforced.

The pattern that I usually use is

```python
cmd = ('bash', '--init-file', 'foo')
os.execvp(cmd[0], cmd)  # never returns
```

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37066] os.execl opening a new bash shell doesn't work if initfile/rcfile provided

2019-05-27 Thread Siming Yuan


Siming Yuan  added the comment:

that works... 
but where does it say arv[0] is the program name?

it seems to be more of a how C works... would be nice if the doc had some 
examples of that.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37066] os.execl opening a new bash shell doesn't work if initfile/rcfile provided

2019-05-27 Thread Anthony Sottile


Anthony Sottile  added the comment:

You want:

os.execl('/bin/bash', 'bash', '--init-file', ...)


argv[0] is supposed to be the program name, your example puts `--init-file` as 
the program name

--
nosy: +Anthony Sottile

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37066] os.execl opening a new bash shell doesn't work if initfile/rcfile provided

2019-05-27 Thread Siming Yuan


New submission from Siming Yuan :

Using os.execl you can open a new bash shell (eg, using python to process some 
env before opening a new shell.

$ echo $SHLVL
1
$ ~/.pyenv/versions/3.6.4/bin/python3
Python 3.6.4 (default, Feb  5 2018, 16:53:35)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.execl('/bin/bash', '')
$ echo $SHLVL
2

Doing the above works with just /bin/bash no arguments. (notice SHLVL 
incrementing)

But providing your own custom --init-file or --rcfile, doesn't.
eg - /bin/bashrc --rcfile 

$ echo $SHLVL
1
$ ~/.pyenv/versions/3.6.4/bin/python3
Python 3.6.4 (default, Feb  5 2018, 16:53:35)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.execl('/bin/bash', '--rcfile','/users/me/venv/bin/activate')
$ echo $SHLVL
1

this can be replicated in Python 3.5 to 3.7

can be worked-around if using a wrapper.sh file with:
#! /bin/bash
exec /bin/bash --rcfile /users/me/venv/bin/activate

and running this file in os.execl() instead.

--
messages: 343654
nosy: siming85
priority: normal
severity: normal
status: open
title: os.execl opening a new bash shell doesn't work if initfile/rcfile 
provided
versions: Python 3.5, Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com