0

I am trying to create "avd" from python script using command : android create avd -n avd1 -t android-19 -s QVGA -b x86

Everytime i run this command through Terminal i get avd created but if i am running same command from python script i a getting error which says that "android" command was not found.

Python script:

#!/usr/bin/env python

import sys, os

def main():
    cmd = "android create avd -n avd1 -t android-19 -s QVGA -b x86"
    print cmd
    os.system(cmd)

main()

What could be the possible error.

Environment : Ubuntu 13.04 Path variable set to: export PATH=$PATH:~/android-sdks/tools/:~/android-sdks/build-tools/:~/android-sdks/platform-tools/:~/android-sdks/

1

1 Answer 1

1

From Python's documentation:

Changes to sys.stdin, etc. are not reflected in the environment of the executed command.

os.system has limitations. The subprocess module is preferable.

Try:

import subprocess

cmd = "android create avd -n avd1 -t android-19 -s QVGA -b x86"
subprocess.call(cmd.split())
Sign up to request clarification or add additional context in comments.

7 Comments

i am getting an error like : Traceback (most recent call last): File "Test.py", line 6, in <module> subprocess.call(cmd.split()) File "/usr/lib/python2.7/subprocess.py", line 524, in call return Popen(*popenargs, **kwargs).wait() File "/usr/lib/python2.7/subprocess.py", line 711, in init errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1308, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory
What is the value of os.environ['PATH']? Did you set the $PATH variable correctly?
Value of $PATH is there in the question itself.
I got the subprocess command running. "shell=True" was missing in the command. But still same issue that android is not found.
Do a print os.environ['PATH'] and see what it gives you. It sounds like your Python runtime did not get the correct PATH.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.