469,587 Members | 2,693 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,587 developers. It's quick & easy.

calling source command within python

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
Jul 21 '08 #1
3 9227
Jie wrote:
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
>>import os
os.system("source .bashrc")
sh: source not found and stuff
256

? I get

$ python
>>import os
os.system("source .bashrc")
/... stuff printed by my .bashrc file .../
0

What happens if you do
>>import os
os.system("bash .bashrc")
instead?

</F>

Jul 21 '08 #2
mk
Jie wrote:
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.
Jul 21 '08 #3
Jie <Ji*****@gmail.comwrites:
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
Jul 25 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.