Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

invoking rsh and testing for success/failure

by Anonymous Monk
on Apr 01, 2005 at 15:43 UTC ( #444222=perlquestion: print w/replies, xml ) Need Help??

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

I am prompting the user for some information, once they enter that info my script uses that that information to locate a file via ls in a directory via a rsh command. If the file does not exist the system responds with a "No match." and my perl script continues on as if everything is ok. I know I need to set up an if statement, but am uncertain what I need to check for....I am new to perl and have hunted on the web, but to no avail....can you all help? Thanks, T

2005-04-02 Edited by Arunbear: Changed title from 'perl question', as per Monastery guidelines

  • Comment on invoking rsh and testing for success/failure

Replies are listed 'Best First'.
Re: invoking rsh and testing for success/failure
by ikegami (Pope) on Apr 01, 2005 at 15:53 UTC
    if (`rsh ...` =~ /No match/) { die("File not found.\n"); }

    `` returns the STDOUT of the command as a string instead of displaying it. If you need both STDOUT and STDERR, redirect STDERR to STDOUT (by addiging "2>&1" to the command).

      Thanks a bunch!! I finally figured it out and it works! really appreciate your help though. Have a great weekend! T
Re: invoking rsh and testing for success/failure
by RazorbladeBidet (Friar) on Apr 01, 2005 at 16:55 UTC
    Alternatively, you can check the return code of the execution. (see perlvar)
    my $cmd = "rsh $file"; # or whatever my $output = qx/$cmd/; # qx// is the same as `` my $rc = $?; # $? is a special Perl variable if ( $rc ) { print STDERR "No Match\n"; # you just want to print and continue, ri +ght? }
    --------------
    "But what of all those sweet words you spoke in private?"
    "Oh that's just what we call pillow talk, baby, that's all."

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2020-11-26 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?