I'm making some changes to an existing script, ScriptA.pl, which copies a file and calls an external program to do some work on the copy. Everything is fine until the source file is read-only, a result of another automated program that creates it. One requirement of the project is to automate everything, so I need to patch ScriptA.pl to copy the source file and then strip off the read-only attribute if it exists.
Since everything is run off of WinXP machines, I thought the xcopy command would be the perfect tool for the job. As a test, I ran the following in the command prompt:
xcopy d:basedir\tools\ScriptA\bin\AS3.udb d:basedir\working3\build\ScriptA\ /r /y /iWhere basedir is my base directory. The command worked perfectly, but I can't seem to properly translate that into perl code. What I ended up with was the following line, choosing system in order to capture the return value:
system('xcopy', "\"$und_db\"", "\"$out_dir/\"", '/r', '/y', '/i')$und_db is the file path of the source file, $out_dir is the destination for the copy. I get the following output on the screen:
Does d:/basedir/working3/build/ScriptA/ specify a file name or directo
+ry name on the target (F = file, D = directory)? _d_
File creation error - Cannot create a file when that file already exis
+ts.
I can't understand the file creation error since I deleted the existing copy to make sure it worked. I also don't understand why the prompt even appears, as the /i parameter should force xcopy to assume directory. Removing the / in the system call fixes the prompt issue, but the file fails to copy and xcopy doesn't give any errors to indicate why. Removing the quotes around the variable names gives the error "Invalid number of parameters". Clearly the problem is related to how I wrote the system call, but I'm totally stumped as to what the problem is. Any help is appreciated.