os.system(<command>) execution through Python :: Limitations?
Question: I'm writing a python (ver 2.7) script to automate the set of commands in this
Getting Started [example](http://inotool.org/quickstart) for
[INOTOOL](http://inotool.org/).

Problem: When I run this entire script, I repeatedly encounter these errors:

    
    
    Current Directory is not empty  
    No project is found in this directory  
    No project is found in this directory  
    

But, when I run a first script only up till the code line marked, and manually
type in the next three lines, or when I run these last three lines (starting
from the "ino init -t blink" line) after manually accessing the beep folder,
then I am able to successfully execute the same code.

Is there a limitation with os.system() that I'm encountering?

My code:

    
    
    import os,sys  
    def upload()  
        os.system("cd /home/pi/Downloads")  
        os.system("mkdir beep")  
        os.system("cd beep") #will refer to this code junction in question description  
        os.system("ino init -t blink")  
        os.system("ino build")  
        os.system("ino upload")  
        sys.exit(0)
    


Answer: Yes, when `os.system()` commands are run for `cd` , it does not actually
change the current directory for the python process' context. From
[documentation](https://docs.python.org/2/library/os.html#os.system) \-

> **os.system(command)**
>
> Execute the command (a string) in a subshell. This is implemented by calling
> the Standard C function system(), and has the same limitations. Changes to
> sys.stdin, etc. are not reflected in the environment of the executed
> command.

So even though you are changing directory in os.system() call, the next
os.system call still occurs in same directory. Which could be causing your
issue.

You shoud try using
[`os.chdir()`](https://docs.python.org/2/library/os.html#os.chdir) to change
the directory instead of `os.system()` calls.

The Best would be to use `subprocess` module as @PadraicCunningham explains in
his answer.

