redirection, relative paths and subprocess cwd

Issue #9 resolved
Former user created an issue

There are some cases where I would like to use redirection to relative paths and would like those to be relative to cwd.

Perhaps something like:

import sarge
sarge.run('mysqldump mydb | gzip > mydb.sql.gz', cwd='/my/backups/')

Presently this always opens the output file relative to os.getcwd() and then the subprocess is run relative to cwd. I would like the redirection evaluated against Popen's cwd option, if present.

Here's a naive change I was playing around with to accomplish this:

diff -r decaade3fdd5 sarge/__init__.py
--- a/sarge/__init__.py Fri Jun 14 17:40:12 2013 +0100
+++ b/sarge/__init__.py Sat Jun 15 20:33:04 2013 +0000
@@ -1039,6 +1039,8 @@
             else:
                 mode = 'ab'
             if isinstance(fn, string_types):
+                cwd = self.kwargs.get('cwd', '')
+                fn = os.path.join(cwd, fn)
                 stream = open(fn, mode)
                 with self.lock:
                     self.opened.append(stream)

Comments (1)

  1. Log in to comment