Trouble with command line execution or R script file from within Python shell
Question: I'm currently using the `optparse` package cast an R script file as a command
line executable file that accepts C-style long and short flags. The program is
running on Ubuntu. The execution of the overall application is controlled by a
Python script that (1) first uses `os.system` to call `chmod` on the
`script.R` file as follows:

    
    
    import os 
    os.system("chmod +x script.R; export PATH=$PATH:`pwd`")
    

I then attempt to execute the program, again from within Python using
`os.system` as follows:

    
    
    program_call = "script.R --arg1 1"
    os.system(program_call) 
    

This returns the error:

    
    
    sh: 1: script.R: not found
    32512
    

The really puzzling thing is that this was working fine just a day ago and now
it's erroring out. I'm developing this application with several other people,
so I'm wondering if this could be caused by a change in my administrative
permissions. I've verified that all necessary file are contained within the
current working directory.


Answer: The change to the `PATH` environment variable in your first call to
`os.system` won't carry over to the second call, since it's a separate shell
process. If you instead modify `PATH` within Python, it should work. Try

    
    
    os.environ['PATH'] += ":" + os.getcwd()
    os.system("chmod +x script.R")
    program_call = "script.R --arg1 1"
    os.system(program_call) 
    

