Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Error when using system("clear") command

by valavanp (Curate)
on Jul 17, 2007 at 11:35 UTC ( #627004=perlquestion: print w/ replies, xml ) Need Help??
valavanp has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

In the below script after executing the wmdist command, it is suppose to send the success status to a file ( which is in if loop). It is doing correctly. But if there is no ouput for the failed status, it is writing the previous output i.e success output to the failed text file. This should not happen. My requirement is my file should be empty if there is no output for failed status. I have tried giving system(“clear”) command after wmdist command. But while executing the program it is throwing a error “ clear is not a operable command like that”

#! /usr/bin/perl -w #use warnings; #use strict; use Net::SMTP; use MIME::Lite; ###Deleting the old files unlink <D:/report/*.txt>; ###Input from the User print "\n Pls give all your inputs in CAPS\n"; print "Enter the dist id of the package\n"; chop($input=<STDIN>); print "Enter the gateway name of the package\n"; chop($division=<STDIN>); print "Enter the version of the package\n"; chop($version=<STDIN>); ### Declarations my %id=("HTCHSTCGW1"=>"abc\@abc.in", "HTCHTDLGW1"=>"def\@def.in", "HTCHMROGW1"=>"ghi\@ghi.in", "HTCHAM4GW1"=>"jkl\@jkl.in"); my %cc=("HTCHSTCGW1"=>"ppp\@ppp.in", "HTCHTDLGW1"=>"ppp\@ppp.in", "HTCHMROGW1"=>"ppp\@ppp.in", "HTCHAM4GW1"=>"ppp\@ppp.in"); my $mail_host='10.101.26.28'; my $From_address='admin@abc.in'; my $body="Hi, Monthly Patches were distributed to the hosts in $division.\n Results of the $version patches"; ###Distribution Status based on Input if($version eq "2K") { system("wmdist -e $input SUCCESS > 2K_success.txt"); system("wmdist -e $input FAILED > 2K_failed.txt"); system("wmdist -e $input WAITING > 2K_waiting.txt"); } if($version eq "2K3") { system("wmdist -e $input SUCCESS > 2K3_success.txt"); system("wmdist -e $input FAILED > 2K3_failed.txt"); system("wmdist -e $input WAITING > 2K3_waiting.txt"); } if($version eq "XP") { system("wmdist -e $input SUCCESS > XP_success.txt"); system("clear"); system("wmdist -e $input FAILED > XP_failed.txt"); $|=1; system("wmdist -e $input WAITING > XP_waiting.txt"); } my $To_address=$id{$division}; my $cc_address=$cc{$division}; $msg=MIME::Lite->new( From => $From_address, To => $To_address, Cc => $cc_address, Subject =>'Monthly Patches Rollout Distribution Status', Type =>'multipart/mixed' ); $msg->attach( Type =>'Text', Data => "$body" ); if ( $version eq "2K3") { $msg->attach( Type =>'text/html', Path =>'D:/report/2K3_success.txt', Filename =>'2K3_success.txt', Disposition => 'attachment' ); $msg->attach( Type =>'text/html', Path =>'D:/report/2K3_failed.txt', Filename =>'2K3_failed.txt', Disposition => 'attachment' ); $msg->attach( Type =>'text/html', Path =>'D:/report/2K3_failed.txt', Filename =>'2K3_waiting.txt', Disposition => 'attachment' ); } if ( $version eq "2K") { $msg->attach( Type =>'text/html', Path =>'D:/report/2K_success.txt', Filename =>'2K_success.txt', Disposition => 'attachment' ); $msg->attach( Type =>'text/html', Path =>'D:/report/2K_failed.txt', Filename =>'2K_failed.txt', Disposition => 'attachment' ); $msg->attach( Type =>'text/html', Path =>'D:/report/2K_failed.txt', Filename =>'2K_waiting.txt', Disposition => 'attachment' ); } if ( $version eq "XP") { $msg->attach( Type =>'text/html', Path =>'D:/report/XP_success.txt', Filename =>'XP_success.txt', Disposition => 'attachment' ); $msg->attach( Type =>'text/html', Path =>'D:/report/XP_failed.txt', Filename =>'XP_failed.txt', Disposition => 'attachment' ); $msg->attach( Type =>'text/html', Path =>'D:/report/XP_failed.txt', Filename =>'XP_waiting.txt', Disposition => 'attachment' ); } MIME::Lite->send('smtp',$mail_host,Timeout=>60); $msg->send;

Is there any discrepancies found in the code.

Can anyone correct me where i am wrong.

Thanks in advance for your valuable efforts.

Comment on Error when using system("clear") command
Download Code
Re: Error when using system("clear") command
by regexes (Hermit) on Jul 17, 2007 at 12:05 UTC
    Hello,

    On the presumption that your clear command is trying to clear the screen.
    In this portion of the code..
    if($version eq "XP") { system("wmdist -e $input SUCCESS > XP_success.txt"); system("clear"); system("wmdist -e $input FAILED > XP_failed.txt"); $|=1; system("wmdist -e $input WAITING > XP_waiting.txt"); }
    The command is incorrect?

    I believe it should be
    system("cls");
    At least when I run cls on an XP machine, it clears the screen.

    regexes


    -------------------------
    Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan "press on" has solved and always will solve the problems of the human race.
    -- Calvin Coolidge, 30th President of the USA.
      int Clear() { //clears and sets the cursor to home position std::cout << "\x1B[2J"; std::cout << "\x1B[0;0H"; }
      this is the appropriate method for both *nix and win. Using the system("clear") | system("cls") is not a safe practice.
Re: Error when using system("clear") command
by andreas1234567 (Vicar) on Jul 17, 2007 at 14:20 UTC
    Is it possible to capture the output of the command to a variable first, then act depending on the whether the variable is defined or not?
    use strict; use warnings; use Fatal qw(open close); # make open, close die on failure if($version eq "XP") { my $success = `wmdist -e $input SUCCESS`; if ($success) { my $FH = undef; open($FH, "> XP_success.txt"); print $FH, $success; close $FH; } else { # no output from success command } }
    The backtick operator is described in perlop.
    --
    Andreas

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://627004]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (14)
As of 2014-10-21 15:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (105 votes), past polls