calling source command within python

J

Jie

Hi all,

i'm having trouble executing os.system('source .bashrc') command
within python, it always says that source not found and stuff. Any
clue?

Thanks,
Jie
 
F

Fredrik Lundh

Jie said:
i'm having trouble executing os.system('source .bashrc') command
within python, it always says that source not found and stuff. Any
clue?

like in

$ python sh: source not found and stuff
256

? I get

$ python /... stuff printed by my .bashrc file .../
0

What happens if you do

instead?

</F>
 
M

mk

Jie said:
Hi all,

i'm having trouble executing os.system('source .bashrc') command
within python, it always says that source not found and stuff. Any
clue?

It _might_ be that the shell it fires up is /bin/sh and this in turn is
not bash.

Anyway, it's better to use subprocess / Popen for this sort of operation.
 
G

Glenn Hutchings

Jie said:
i'm having trouble executing os.system('source .bashrc') command
within python, it always says that source not found and stuff. Any
clue?

There's no 'source' program; it's a shell builtin. Even if there was, it
almost certainly wouldn't do what you want. The .bashrc file is supposed
to contain settings applying to the current shell, and os.system() runs in
a subshell, so the settings will only affect that shell.

If you're doing this to set environment variables, try modifying os.environ
instead.

Glenn
 

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

Forum statistics

Threads
474,270
Messages
2,571,101
Members
48,773
Latest member
Kaybee

Latest Threads

Top