Link to home
Start Free TrialLog in
Avatar of ghosting
ghosting

asked on

xcopy gives invalid drive specification

Hello,

I am still kinda of new to PERL programming, and need some help with system commands, pipes, and network shares / drives on Windows.  I am trying to XCOPY a file to a network drive or share, but I am getting "Invalid Drive Specification" when I run the script from CGI.  If I drop down to command line, and simply DOS XCOPY the files, it works fine.

What do I need to specify for PERL so that it KNOWS about my network drives and shares?  Why is it that when I try it from DOS it works fine, but when I run it from my script it fails with "Invalid Drive Specification"?

        my $cmd = 'xcopy '.$datafile.' '.$mailpickup.'';
        local *ALERTOUT = IO::File->new_tmpfile;
        local *ALERTERR = IO::File->new_tmpfile;
        local *ALERTIN = IO::File->new_tmpfile;
        my $pid = open3(">&ALERTIN", \*ALERTOUT, ">&ALERTERR", $cmd);

I am using IPC::Open3 to make the system calls and read the STDOUT & STDERR into arrays for parsing so I can check the results of the operation.  I can post the rest of code if needed, but I've tried replacing the $CMD arguments with something simple like "dir" and it works fine, no errors.  So I think it's got something to do with the network aware drives and shares available to PERL, please help...

Thanks in advance,
G
Avatar of Kim Ryan
Kim Ryan
Flag of Australia image

How do you specify the netowork drive letter? You may need to say something like
 xcopy F:\\some\\file.txt G:\\other\\file.txt

The following gives more detail
http://aspn.activestate.com/ASPN/docs/ActivePerl/5.8/faq/Windows/ActivePerl-Winfaq8.html#When_I_try_to_open_a_file_I_get
Avatar of ghosting
ghosting

ASKER

I am not convinced this is the problem, the single quote vs double quote issue with escaping the "\" character.  To be sure, I had my subroutine print out the $CMD argument to the browser, to check what was being escaped...

xcopy C:\XAOSys\var\www\linepull\config\Error_report.txt \\erp2\pickup\

is the actual output I am getting from my routine.  Yet I still get invalid drive specification... WHY?
I was well aware of the "\" escaping, my editor warns me if I don't properly escape and close something in quotes, single or double.  I use eclipse, http://e-p-i-c.sourceforge.net/ which ROCKS!

I've got to wrap up for today, but any suggestions on how or why this doesn't work and what to make it work, would be most appreciated.  

Thanks for all your responses,
G
I agree with teraplane it is probably an escaping issue.
In any case, the perlscript is fine as I have posted it below -- as in, it works.
I suggest you use the below and replace test.txt with your file, and compy and share with the appropriate data.  If it still fails you need to look at your perl installation, your windows installation. but there is no point in looking further at the script. It works.


use IO::FILE;
use IPC::Open3;

$datafile = "C:\\test.txt";
$mailpickup = "\\\\compy\\share\\";

my $cmd = 'xcopy ' . $datafile . ' ' . $mailpickup;

        local *ALERTOUT = IO::File->new_tmpfile;
        local *ALERTERR = IO::File->new_tmpfile;
        local *ALERTIN = IO::File->new_tmpfile;
        my $pid = open3(">&ALERTIN", \*ALERTOUT, ">&ALERTERR", $cmd);


ASKER CERTIFIED SOLUTION
Avatar of clockwatcher
clockwatcher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks clockwatcher,

It totally was IIS, darn it!  I simply changed the permissions to run as a standard domain admin with rights to all my network shares, viola!  A little scary, so I think I'll create a Power User or Backup operator and make that user my IIS anonymous user, since I need access to several domains for my archiving project.

Thanks and have a good one...
G