smanicka has asked for the wisdom of the Perl Monks concerning the following question:

I am logged on as an admin in my system and I want to use the lpr command to transfer an ascii file over to an as400 system.The reason being only then can the as400 understand the file format.
#!usr/bin/perl -w use strict; my $cmd=qw(lpr -S SYSTEMX -P QGPL/SPYVIEW -o l C:\\ABCDEFGH.txt); system($cmd) or die "cannot do this";
This is what happens: It repeats this message 7 times:"Usless Use of a constant in void context at move_files.pl line 3" and it opens the text file.Then when I close the file,it says "cannot do this at move_files.pl line 4"

Could anybody tell me where I am wrong please.It works fine when i just use the lpr command from my command prompt.I use activestate perl and am on a windows machine. Thanks

-Sandhya

UPDATE: It now does not show up with the message 7 times.But other than that it says cannot do this.

Replies are listed 'Best First'.
Re: lpr command from perl not working.
by bingos (Vicar) on Feb 11, 2009 at 21:25 UTC

    $cmd ends up containing C:\ABCDEFGH.txt

    You perhaps wanted @cmd?

    #!usr/bin/perl -w use strict; my @cmd=qw(lpr -S SYSTEMX -P QGPL/SPYVIEW -o l C:\\ABCDEFGH.txt); system(@cmd) or die "cannot do this: $!";
      I did that and now it doesnt give the actual usless something 7 times.But it still says cannot do this at line 4
        system() returns the exit value of the command being run, which (on *nix systems, anyway) will be zero on success, so "system($foo) or bar()" will do bar() when $foo succeeds, not when it fails.
Re: lpr command from perl not working.
by linuxer (Curate) on Feb 11, 2009 at 21:50 UTC

    Please check perldoc -f system to see how to check if a call of system() was successful or not.

      Thank you Thank you Thank you..It finally works..
Re: lpr command from perl not working.
by repellent (Priest) on Feb 11, 2009 at 21:28 UTC
    Change $cmd to @cmd. You're essentially calling:
    system('C:\\ABCDEFGH.txt') or die "cannot do this";