I have Perl code that uses the system() function to call robocopy.exe, but it looks like it’s mangling the parameters. I’m using Chef, which bundles Perl via Cygwin – “This is perl, v5.8.8 built for msys-64int”.
I think Cygwin is escaping some characters, but system() won’t show me what it’s actually passing to the shell, so I don’t know how to format the call correctly.
my $robocopyCmd = "robocopy.exe /a-:r /r:30 /w:10 c:/folder1 c:/folder2";
print "DEBUG: " . $robocopyCmd . "\n";
system($robocopyCmd);
And here is the output.
DEBUG: robocopy.exe /a-:r /r:30 /w:10 c:/folder1 c:/folder2
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows :: Version XP010
-------------------------------------------------------------------------------
Started : Wed Jun 20 10:33:05 2012
Source - R:\30\
Dest - W:\10\
Files :
Options : /COPY:DAT /A-:R /R:1000000 /W:30
------------------------------------------------------------------------------
ERROR : Invalid Parameter #4 : c:/folder1
When I cut and paste the debug output into a shell (even a Cygwin shell) it runs just fine. However, look in the robocopy output for where it tells you the Source and Dest. Notice how it changed my argument of /r:30 to R:\30\ ?
It seems like something (cygwin or perl or system()) is automatically escaping some characters before passing them to the shell. The problem is there’s no way for me to see what it’s changing, so I don’t know how to customize my command to work properly!
Note that the behavior is exactly the same if I use backticks instead of the system() function.
never escapes anything. What could it possible be escaping from?
The problem is that you’re trying to run a Windows shell command in the bourne shell.
is short for
on unix systems (including unix emulation layers such as the cygwin build of Perl). Does the following work?