Python, os.system fails when script not in same folder
Question: I have a bat.bat file containing the following command: **'setup.py build'**  

I have a script that executes this bat command using:  
`os.system('E:/bla/FPtest/retryURL/Temp_installed/bat.bat'`  

If i run the script from the same folder as the bat.bat ... it works perfectly
perfectly.

If i run it in ANY other folder, the following error is returned.

    
    
    **'setup.py'** is not recognized as an internal or external command, operable program or batch file.
    

I have also tried `subprocess.Popen` which returns the same result **BUT** it
includes this at the top: `C:\Eclipse\Workspace\example>setup.py build` ...
mmmmmm ...

**UPDATE:**

I have decided to run the os.system command in the same directory where the
bat.bat file is kept (this is ALSO the directory where the setup.py is stored)

the call should be so simply now.  

    
    
    import os
    os.system('bat.bat')     note: (run from pydev)
    

**result:**

    
    
    E:\App\FPtest\retryURL\Temp_installed>setup.py build 
    Traceback (most recent call last):
      File "C:\Python31\lib\site.py", line 56, in <module>
        import os
      File "C:\Python31\lib\os.py", line 380, in <module>
        from _abcoll import MutableMapping  # Can't use collections (bootstrap)
      File "C:\Python31\lib\_abcoll.py", line 49
        class Hashable(metaclass=ABCMeta):
                                ^
    SyntaxError: invalid syntax
    

Additional note:  

If i run any 'simple' .bat file everything works fine. and if i run the .bat
file outside of the interpreter it too works fine ... which leads me to
believe it is the content of the .bat file that is causing the problem the
content is: `setup.py build`.  
In this case the content of the .bat file executes an cx_freeze command to
freeze and exe but the above error is what is returned when I try this

**UPDATE:**

It appears running the 'os.system('bat.bat')or the subprocess equivalent
successfully executes the .bat file if run from the standard python
interpreter. So it is only unsuccessful if run from Pydev


Answer: In Windows 2000 and beyond the `.py` extension is associated with an open
command that runs the interpreter. This is actually done during installation.
But inorder to run the python script via the interpreter, either the script
should be in the current directory or should be in one of the directories
concatenated in the path environment variable.

In your case if setyp.py is present in present in some and the path is
absolute you can do the following

    
    
    path=%path%;<directory containing setup.py>
    

On the other hand, if setup.py is at a relative directory from your batch file
which is not an absolute path. You need to specify the full relative path from
your current batch file location. Something like

    
    
    ..\<sub directory>\setyp.py #If the script is below the current path
    

or

    
    
    .\<sup directory>\setyp.py #If the script is above the current path
    

Note*** You can also run the script without an extension (Not Recommend) if
`.py` is present in the PATHEXT environment variable.

