On Mar 26, 10:33 pm, skunkwerk <[EMAIL PROTECTED]> wrote: > On Mar 26, 8:05 am, Jeffrey Froman <[EMAIL PROTECTED]> wrote: > > > > >skunkwerkwrote: > > > p = subprocess.Popen(['rename','-vn','s/(.*)\.htm$/ > > > model.html/','*.htm'],stdout=subprocess.PIPE,stderr=subprocess.PIPE) > > > print p.communicate()[0] > > > > i change to print p.communicate()[1] in case the output is blank the > > > first time > > > > this is the output: > > > *.htm renamed as model.html > > > Without shell=True, your glob characters will not be expanded. Hence, the > > command looks for a file actually named "*.htm" > > > > when I add shell=True to the subprocess command, I get the following > > > output: > > > Usage: rename [-v] [-n] [-f] perlexpr [filenames] > > > Here the use of the shell may be confounding the arguments passed. Your > > command will probably work better if you avoid using shell=True. However, > > you will need to perform your own globbing: > > > # Untested (no perl-rename here): > > > command = ['rename','-vn', 's/(.*)\.htm$/model.html/'] > > files = glob.glob('*.htm') > > command.extend(files) > > p = subprocess.Popen( > > command, > > stdout=subprocess.PIPE, > > stderr=subprocess.PIPE, > > ) > > > Jeffrey > > thanks Jeffrey, that worked like a charm!
I'm trying to detect when the subprocess has terminated using the wait() function - but when there is an error with the call to rename (ie the file doesn't exist) rename (when run from the command line just terminates and displays the error). In the code above, though, my call to p.wait() just hangs when rename should throw an error... I've tried adding shell=True but that stops the rename from working. any ideas? thanks -- http://mail.python.org/mailman/listinfo/python-list