os.getlogin() Error

Chris Angelico rosuav at gmail.com
Thu May 4 22:21:36 EDT 2017


On Fri, May 5, 2017 at 12:05 PM, Wildman via Python-list
<python-list at python.org> wrote:
> On Fri, 05 May 2017 09:58:02 +1000, Chris Angelico wrote:
>
>> On Fri, May 5, 2017 at 9:50 AM, Wildman via Python-list
>> <python-list at python.org> wrote:
>>> I'm afraid that won't work.  The user environment is different
>>> than root.  A different set of variables.  However you have
>>> given me a possible workaround.  You can't create a variable
>>> for root unless you are root so that approach is out.  But
>>> it might be possible to create the variable for the user
>>> and access it as root.  I don't have a lot of experience
>>> using os.environ, but I am going to at it closer.
>>
>> When you start a subprocess, it inherits your environment. So you can
>> create an environment variable for yourself, then start the other
>> process.
>
> I solved this problem by passing the user name to the second
> instance as a command line argument.  Works perfectly.  It
> escapes me why I didn't think of this sooner.  I solved the
> os.login problem by not using os.login, since I no longer
> need it. :-)

That works too!

ChrisA



More information about the Python-list mailing list