FAQ
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
---------------------------------------------------

Search Discussions

  • Mmaunder at Sep 17, 2002 at 12:09 pm
    The file can't be found? Sounds like a DOS not a Perl problem.
    On Tue, Sep 17, 2002 at 08:00:06AM -0400, FlashGuy wrote:

    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
    ---------------------------------------------------




    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
  • Sudarshan Raghavan at Sep 17, 2002 at 12:46 pm

    On Tue, 17 Sep 2002, FlashGuy wrote:


    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?
    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 at Sep 17, 2002 at 1:44 pm
    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...

    --
    Tim@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 at Sep 17, 2002 at 11:07 pm

    On Tue, Sep 17, 2002 at 08:00:06AM -0400, FlashGuy wrote:
    Hi,
    Hi FlashGuy,
    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?
    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 at Sep 19, 2002 at 12:31 pm
    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');
    `-----

    --
    Tim@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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedSep 17, '02 at 12:00p
activeSep 19, '02 at 12:31p
posts6
users5
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase