Solved

xcopy gives invalid drive specification

Posted on 2007-03-22
5
3,206 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:ghosting
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 18775921
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
 

Author Comment

by:ghosting
ID: 18776085
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
 
LVL 8

Expert Comment

by:bebonham
ID: 18776511
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
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
ID: 18777233
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
 

Author Comment

by:ghosting
ID: 18781757
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question