By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,688 Members | 1,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,688 IT Pros & Developers. It's quick & easy.

calling source command within python

P: n/a
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
Share this Question
Share on Google+
3 Replies

P: n/a
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

P: n/a
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

P: n/a
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.