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
ghostingAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kim RyanIT ConsultantCommented:
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
0
ghostingAuthor Commented:
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
0
bebonhamCommented:
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);


0
clockwatcherCommented:
If the path isn't the problem then it's probably a permissions problem.   Which webserver are you using?

If you're running IIS and you haven't changed the IIS authentication method for the script (or more typically the directory housing your script), it will be running as a local user account (IUSR_Machinename) and that local user account won't have access to the network.    To change it,  from the IIS MMC navigate to the folder housing your script, right-click (either the directory or the script itself), select Properties, File (or Directory) Security Tab, Anonymous access and authentication control section Edit.., and change the account used for anonymous access to a network account.

If you're using Apache, you'd need to change the service so it's running as an account with network permissions (rather than the LocalSystem account which is the default).  Control Panel, Admin Tools, Services, Apache, right-click, Properties, Log On.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ghostingAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.