Help with 'popen'

J

James Stroud

stephen_b said:
Can someone let me know why this won't work? Thanks.



'\n'

Thanks.

Stephen

Python starts a new shell for each command, so your environment variable
is lost. You probably want this, which makes the variable "permanent".

py> import os
py> os.environ['asdfasdf'] = 'hello'
py> os.popen('echo $asdfasdf').read()
'hello\n'

James
 
T

Tim Roberts

James Stroud said:
stephen_b said:
Can someone let me know why this won't work? Thanks.

'\n'

Python starts a new shell for each command, so your environment variable
is lost. You probably want this, which makes the variable "permanent".

py> import os
py> os.environ['asdfasdf'] = 'hello'
py> os.popen('echo $asdfasdf').read()
'hello\n'

For completeness, let us anticipate the followup question and point out
that "permanent" here means "for this process and any processes that it
spawns". Once the Python session ends, the "asdfasdf" will be lost.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top