Sponsored Content
Top Forums Shell Programming and Scripting [Perl] Capture system call error message. Post 302344976 by ejdv on Tuesday 18th of August 2009 06:25:37 AM
Old 08-18-2009
[Perl] Capture system call error message.

Hi,

I googled a bit, but could not find the answer to my problem.
But I am sure it is a common issue.

I have this code:

Code:
#!/bin/perl -w #-d

use strict;

sub remsh_test()
{
my $host = $_[0];

printf "\n----\n\n";

printf "remsh to $host with system call\n";
my $result = system ("remsh $host hostname");
printf "Contents of \$result :\n";
printf "$result\n";

printf "\n----\n\n";

printf "remsh to $host with backticks\n";
$result = `remsh $host hostname`;
printf "Contents of \$result :\n";
printf "$result\n";

printf "\n----\n\n";

printf "remsh to $host with open\n";
open (RESULT, '-|', "remsh $host hostname");
while (<RESULT>) {
        chomp;
        printf "Contents of \$_ :\n";
        printf "$_\n";
        $result = $_;
        printf "Contents of \$result :\n";
        printf "$result\n";
}
close (RESULT);

printf "\n----\n\n";

} # end sub

# === MAIN ===

foreach my $host ("nbsol151", "nbfuz159") {
        &remsh_test($host);
}

The output is following:

Code:
----

remsh to nbsol151 with system call
nbsol151
Contents of $result :
0

----

remsh to nbsol151 with backticks
Contents of $result :
nbsol151


----

remsh to nbsol151 with open
Contents of $_ :
nbsol151
Contents of $result :
nbsol151

----


----

remsh to nbfuz159 with system call
rcmd: nbfuz159: Unknown host
Contents of $result :
256

----

remsh to nbfuz159 with backticks
rcmd: nbfuz159: Unknown host
Contents of $result :


----

remsh to nbfuz159 with open
rcmd: nbfuz159: Unknown host

So the observation is that, when remsh works on the other host, you are able to capture its output and use it in your program.
But when remsh fails, you cannot capture the error and use it in your program.

I am looking for a way to capture this "rcmd: nbfuz159: Unknown host" and to use it in my program.
And I do not want the see "rcmd: nbfuz159: Unknown host" on my screen.

Any thoughts ?

Thanks in advance,

E.J.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sh Prgram to capture Log message.

Hi All, I have a log file which consists of log messages as follows -> GLOBALCALLID_CLUSTERID_B NEXT * , O(") CHARACTER JOINONBEHALFOF NEXT * , O(") CHARACTER Record 1: Rejected - Error on table IFA_MMV_CDR, column CDRRECORDTYPE.... (1 Reply)
Discussion started by: rahulrathod
1 Replies

2. UNIX for Advanced & Expert Users

how to differentiate system call from library call

Hi, Ho do I differentiate system call from library call? for example if I am using chmod , how do I find out if it is a system call or library call? Thanks Muru (2 Replies)
Discussion started by: muru
2 Replies

3. Shell Programming and Scripting

How to capture status code and echo a message

Im trying to execute application and its return code is below IF Status code=o echo "........" else Staus Code =-2 DJRE then echo "......" Can any one help me how to handle the status code and echo some message. (12 Replies)
Discussion started by: laknar
12 Replies

4. Shell Programming and Scripting

Lay person needs perl help solving error message

Hi, My name is Tex I am past 60 and in need of perl help. My hobby is genealogy and I am using a perl program to display my data on my web pages. I don't even know enough to know how to ask in the right way for the help I need. This program is written in perl it is open and has been updated... (2 Replies)
Discussion started by: tex
2 Replies

5. Shell Programming and Scripting

How to capture actual error message when a command fails to execute

I want to capture actual error message in case the commands I use in my shell script fails. For eg: ls -l abc.txt 2>>errorlog.txt In this case I understand the error message is written to the errorlog.txt and I assume its bacause the return code from the command ls -l abc might return 2 if... (3 Replies)
Discussion started by: prathima
3 Replies

6. Shell Programming and Scripting

PERL SSH call error

I have a Perl Script #!/usr/local/bin/perl $server_name = "info-xyz-05"; my $value = `/usr/bin/ssh -f $server_name /users/salesadm/MGFINFA/bridgerftpup.sh`; The above calls a shell script on another server called bridgerftpup.sh. This script has several commands and needs to call... (2 Replies)
Discussion started by: alfredo123
2 Replies

7. Shell Programming and Scripting

How to call the System command twice in the same perl script...

Hello experts, I have a perl script which looks for the ARGV and then loads the data as per it. Example. #Checking the server to connect if ($ARGV eq 'QA') { $ENV{"ORACLE_HOME"} = "/oracle/product/11.2.0"; $ENV{"PATH"} = "$ENV{'PATH'}:/oracle/product/11.2.0/bin"; ... (1 Reply)
Discussion started by: msrahman
1 Replies

8. Shell Programming and Scripting

Capture all error message in Log file and send the Log file by email

Hi I have a requirement to write a script to capture all errors in a Logfile and send the file in email. If there is any error occurred the subject of email will be ERROR , If there are no error occurred the subject of email will be SUCCESS. So I created a Log file and put the Appropriate... (2 Replies)
Discussion started by: dgmm
2 Replies

9. Programming

C: error in wait system call

i made this program but when i compile this code, compiler make this error, is an error on wait() system call but argumenti is right, or not?: esercizio.c:80:9: error: incompatible type for argument 1 of ‘wait' /usr/include/i386-linux-gnu/sys/wait.h:116:16: note: expected ‘__WAIT_STATUS' but... (4 Replies)
Discussion started by: tafazzi87
4 Replies
ppmtosixel(1)						      General Commands Manual						     ppmtosixel(1)

NAME
ppmtosixel - convert a portable pixmap into DEC sixel format SYNOPSIS
ppmtosixel [-raw] [-margin] [ppmfile] DESCRIPTION
Reads a portable pixmap as input. Produces sixel commands (SIX) as output. The output is formatted for color printing, e.g. for a DEC LJ250 color inkjet printer. If RGB values from the PPM file do not have maxval=100, the RGB values are rescaled. A printer control header and a color assignment table begin the SIX file. Image data is written in a compressed format by default. A printer control footer ends the image file. OPTIONS
-raw If specified, each pixel will be explicitly described in the image file. If -raw is not specified, output will default to com- pressed format in which identical adjacent pixels are replaced by "repeat pixel" commands. A raw file is often an order of magni- tude larger than a compressed file and prints much slower. -margin If -margin is not specified, the image will be start at the left margin (of the window, paper, or whatever). If -margin is speci- fied, a 1.5 inch left margin will offset the image. PRINTING
Generally, sixel files must reach the printer unfiltered. Use the lpr -x option or cat filename > /dev/tty0?. BUGS
Upon rescaling, truncation of the least significant bits of RGB values may result in poor color conversion. If the original PPM maxval was greater than 100, rescaling also reduces the image depth. While the actual RGB values from the ppm file are more or less retained, the color palette of the LJ250 may not match the colors on your screen. This seems to be a printer limitation. SEE ALSO
ppm(5) AUTHOR
Copyright (C) 1991 by Rick Vinci. 26 April 1991 ppmtosixel(1)
All times are GMT -4. The time now is 08:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy