1

I'm having trouble with Python Fabric removing some local files. Yet, I found a related post on StackOverflow with a solution. But I am wondering why does adding 2>&1 at the end fix it?

I can run the following perfectly fine in my terminal:

$ find app/views/ -type f -name '*%%.php' -exec rm {} \;

However when I do a fabric call I get:

$ fab rmcache
[localhost] local: find app/views/ -type f -name '*%%.php' -exec rm {} \;
find: missing argument to `-exec'

Fatal error: local() encountered an error (return code 1) while executing 'find
app/views/ -type f -name '*%%.php' -exec rm {} \;'

0: Why does it require 2>&1 through Fabric, but not locally?

1: Why does this work through Fabric?

def rmcache():
    local("find {0} -type f -name '*%%.php' -exec rm {{}} \ 2>&1;".format('app/views/'));

2: But this does not work through fabric?

def rmcache():
    local("find {0} -type f -name '*%%.php' -exec rm {{}} \;".format('app/views/'));
JREAM
  • 5,025
  • 10
  • 41
  • 80

1 Answers1

1

0: 2>&1 redirects stderr to stdout which means that if your command is throwing an error fabric won't pick it up because it isn't being returned to fabric (See this answer for more details on 2>&1).

1 & 2: My guess is that your code is throwing an error because 'app/views' is a relative path and find requires the directory to exist, therefore you would have to run your fabric command from the directory that contains the app directory. Try using '/full/path/to/app/views' to ensure you are using the correct directory.

Community
  • 1
  • 1
Braden Becker
  • 2,439
  • 18
  • 15