Discussion:
Executing DOS "copy" command from perl script via web interface
FlashGuy
23 years ago
Permalink
Hi,

I have a web interface where I'm executing a compiled perl script. Within the perl script I'm trying to execute a DOS command but its not working properly.
If I put my command in a batch file and execute the batch file from the perl script it works. I know it's because copy is not a program...it's a function inside the command.com
/cmd.exe shell interpreter. That's why it works when it's a batch file...because the batch is implicitly run under the shell interpreter.

This is the line in my perl script that is not quite doing what I want it to do. Copy the file.

system("command.com copy /C d:\test\input.ps e:\test\output.ps");


When I run the above line from a DOS command prompt this is the error I get.

File not found - D:\TEST\INPUT.PS
0 file(s) copied

What wrong?




---------------------------------------------------
FIGJAM
---------------------------------------------------
m***@workzoo.com
23 years ago
Permalink
The file can't be found? Sounds like a DOS not a Perl problem.
...
Sudarshan Raghavan
23 years ago
Permalink
...
As has been pointed out D:\TEST\INPUT.PS is not present. Why don't you use
File::Copy comes with the standard perl distro.

perldoc File::Copy
Tim Musson
23 years ago
Permalink
Hey FlashGuy,

My MUA believes you used PMMail 2000 Standard (2.20.2502) For Windows 2000 (5.1.2600;1)
to write the following on Tuesday, September 17, 2002 at 8:00:06 AM.

F> I have a web interface where I'm executing a compiled perl script.
F> Within the perl script I'm trying to execute a DOS command but its
F> not working properly. If I put my command in a batch file and
F> execute the batch file from the perl script it works. I know it's
F> because copy is not a program...it's a function inside the
F> command.com /cmd.exe shell interpreter. That's why it works when
F> it's a batch file...because the batch is implicitly run under the
F> shell interpreter.

F> This is the line in my perl script that is not quite doing what I
F> want it to do. Copy the file.

F> system("command.com copy /C d:\test\input.ps e:\test\output.ps");

First, you could just have Perl do the file copy... Check out
perldoc -m "file::copy"

F> When I run the above line from a DOS command prompt this is the
F> error I get.

F> File not found - D:\TEST\INPUT.PS
F> 0 file(s) copied

This error is coming from the copy command, and is indicating the
file does not exist...
--
***@Musson.net
Flying with The Bat! eMail v1.61
Windows 2000 5.0.2195 (Service Pack 2)
The days of the digital watch are numbered.
Michael Kelly
23 years ago
Permalink
Post by FlashGuy
Hi,
Hi FlashGuy,
...
In Perl, backslashes escape the character that follows them, just like in C. If
you want a literal backslash, you need either "\\" or '\':

system("command.com copy /C d:\\test\\input.ps e:\\test\\output.ps");

or

system('command.com copy /C d:\test\input.ps e:\test\output.ps');

The latter example is probably perferable.

But that still doesn't explain why it lists the file as "D:\TEST\INPUT.PS",
which seems correct (I would expect it to say something like "D: EST NPUT.PS".)
But I've never messed with DOS, so I can't be sure.
--
Michael
Tim Musson
23 years ago
Permalink
Hey Michael,

My MUA believes you used Mutt/1.3.27i
to write the following on Tuesday, September 17, 2002 at 7:06:32 PM.

MK> In Perl, backslashes escape the character that follows them, just
MK> like in C. If you want a literal backslash, you need either "\\"
MK> or '\':

MK> system("command.com copy /C d:\\test\\input.ps e:\\test\\output.ps");

MK> or

MK> system('command.com copy /C d:\test\input.ps e:\test\output.ps');

MK> The latter example is probably perferable.

MK> But that still doesn't explain why it lists the file as "D:\TEST\INPUT.PS",
MK> which seems correct (I would expect it to say something like "D: EST NPUT.PS".)
MK> But I've never messed with DOS, so I can't be sure.

Works just like you said... I just tested using type instead of copy.
,----- [ output of running t.pl from the root of T: - it types it's self ]
| T:\>t.pl
| #!perl
| # This file is T:\t.pl
| use strict;
| use warnings;
| system("cmd /c type T:\\t.pl");
| system('cmd /c type T:\t.pl');
|
| #!perl
| # This file is T:\t.pl
| use strict;
| use warnings;
| system("cmd /c type T:\\t.pl");
| system('cmd /c type T:\t.pl');
`-----
--
***@Musson.net
Flying with The Bat! eMail v1.61
Windows 2000 5.0.2195 (Service Pack 2)
I was the next door kid's imaginary friend.
Continue reading on narkive:
Loading...