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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.