1

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.

1
  • So far the best I've come up with is to rm -rf the git repo, re-clone it, and shut down all but one terminal window. for some reason this works and the program stops throwing the error. still no idea why this was happening in the first place Commented Sep 15, 2015 at 22:33

1 Answer 1

1

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) 
Sign up to request clarification or add additional context in comments.

Comments

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.