views:

464

answers:

1

I have written a python script that uses subprocess to call robocopy to sync log files from a remote host.

Like so:

program = 'Robocopy'
options = ['/S']
args.append(program)
args.append(options)
args.append('\\\\%s\%s' % (hostname, source_path))
args.append(local_path)
proc = subprocess.Popen(args=args, shell=True, stdout=cmd_log, stderr=error_log)

where source_path is the path on the remote host and local_path is the path on local host (both UNC paths). The code typically runs in a daemon process and gets kicked off every few hours. It is also possible to runs this code directly on the command prompt. It appears that sometimes when it is running in a daemon process I get an error from Robocopy:

Error code 6: 'The handle is invalid'

But when I run this on the command prompt I get no errors. From what I found in a web search this may be related to file handles that are already open on the files being transferred. Does anyone have more information on this error and ways to avoid it?

+1  A: 

Google searches for "robocopy handle is invalid" suggest you might find success by using the /b option for "backup mode".

Even if that doesn't work, I'd suggest adding code to output the filenames as they are being copied (or log it), and once you've identified the specific failing file, you may well also realize what the problem is.

Peter Hansen
Thanks! I'll give this a try and let you know how it turns out.
noahd