472,127 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

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 9959
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 Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.