I’m having some difficulty calling something external on the command line. The gist is something like a build tool, but I’d like it to be more configurable. I’m trying to create a plugin that runs arbitrary commands when a file is saved. For instance, I’m working on a new project using CoffeeScript and, and when I save a CoffeeScript or JavaScript file, I want to run a rake task to compile the assets together. The catch is that I want to do it only in one directory since that’s the only project I’m currently using CoffeeScript in. Anyway, I have everything working the way I want except the command doesn’t execute.
def perform_action(self, action):
name = action.get("name")
command = action.get("command")
if not command:
print 'Action ' + name + ': No command supplied'
return
wd = action.get("working_dir")
if wd:
os.chdir(wd)
print 'Performing action: ' + name + ' (' + command + ') in ' + os.getcwd()
subprocess.Popen(command, cwd=wd, shell=True)
In this particular case, the working directory is
/Users/phillip/Development/Projects/Self/Web/Grounect/client
and the command is
rake assets:compile:javascripts
It may make a difference that I’m using RVM and have a trusted .rvmrc in this directory. The rake task works if I run it on the command line myself.
In addition to the subprocess.Popen you see here, I’ve also tried os.system, subprocess.call, and something else that I can’t now remember. I’ve searched around on this forum, as well as Google, and have tried the various nuggets that apparently work for other people.
I’d be extremely appreciative if someone could show me what I’m doing wrong.
Thanks.
EDIT: I’m on Mac OS X 10.7.3 and ST2 2178.