Re: call from pthon to shell
On 02/12/2013 05:38 AM, Bqsj Sjbq wrote:
> >>> import os
> >>> os.system("i=3")
> >>> os.system("echo $i")
> why i can not get the value of i?
os.system is only defined to give the return value (exit code) of the
However, one way to get the output of shell commands is to use subprocess.
x = subprocess.check_output( [ "echo", "3,5,7" ] )
However, bash built-ins are not executables; nor is shell expansion
performed; so you will actually need to do something like:
x=subprocess.check_output( [ "bash", "-c", "i=3; echo $i" ] )
To get the result you're interested in.
There may be better ways to get the result you want.... but hopefully
you understand the problem better.
|All times are GMT. The time now is 11:52 PM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.