![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's | manas6 | UNIX for Dummies Questions & Answers | 0 | 06-05-2008 03:44 AM |
| capture ftp return code..PLZ HELP | anju | Shell Programming and Scripting | 3 | 04-03-2008 07:08 AM |
| asking about return code | naamas03 | Shell Programming and Scripting | 3 | 08-28-2007 01:53 AM |
| return code of a process | filedeliver | High Level Programming | 1 | 04-18-2007 10:42 PM |
| Return Code of tar in AIX | dupeng | AIX | 3 | 02-22-2004 09:05 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Return Code of multiple inner executions
Need some clarification on two topics and I apologize for the long post.
Topic 1). I have a PERL script which sends output to the console. This is executed like a daemon script. I would like to capture the "print" commands of the script to a log file. How can this be done. Topic 2) Within the same PERL program I have a call to a Shell script whose return status code is captured. However within the Shell script the last line of execution is a call to java program as "java java_pgm config_file arg_1" Within the java program, an explicit exit status of "1" is returned if there are any issues encountered in the java program execution; else "0" is returned. The issue is when the java program has encounters exception. In this situation the shell script returned a value of 256 and the java program returned the following messages to the console. javax.mail.internet.AddressException: Illegal whitespace in address in string ``. .'' at javax.mail.internet.InternetAddress.checkAddress(InternetAddress.java(Compiled Code)) at javax.mail.internet.InternetAddress.parse(InternetAddress.java(Compiled Code)) at javax.mail.internet.InternetAddress.parse(InternetAddress.java:529) at javax.mail.internet.InternetAddress.parse(InternetAddress.java:506) at com.xxxxx.utilities.emailnotifier.EmailNotifier.getMailMessage(EmailNotifier.java:274) at com.xxxxx.utilities.emailnotifier.EmailNotifier.main(EmailNotifier.java:75) Any ideas as to how to why a value of 256 was returned as opposed to either a "1" or a "0". I did not write the java program. Thanks Last edited by jerardfjay; 05-17-2005 at 10:14 AM. Reason: remove specific |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Quote:
This is because the java application is exiting due to an uncaught exception, and never encounters the exit(1); statement in it's code. In short it's baddly written code. |
|
#3
|
|||
|
|||
|
For Q #1 -
redirect the output to a logfile like this Code:
perl myscript.pl > ~/logfile |
|
#4
|
|||
|
|||
|
Quote:
Jerardfjay Last edited by jerardfjay; 05-18-2005 at 04:28 AM. Reason: better reason for request |
|
#5
|
|||
|
|||
|
Quote:
open (LOGFILE, $logfile); select (LOGFILE); print 1; . . print 2; . . The only issue concern that I have for this method is that, I don't believe that STDERR will be redirected to the logfile. Note to keep in mind is that "select (Filehandle)" is a stick operation. It works well in this situation, however if you have a need to make interaction with the user from within the program you have to explicitly specify select (STDOUT) to redirect output to console again. Jerardfjay Last edited by jerardfjay; 05-20-2005 at 05:00 AM. Reason: explained the select operator |
|
#6
|
|||
|
|||
|
There is I/O redirection in Perl. Try this:
Code:
#!/usr/bin/perl
{
local *STDOUT;
local *STDERR;
open FILE, ">>log.txt" || die "Cannot write to log file!";
open STDOUT, ">&FILE" || die "Cannot redirect STDOUT";
open STDERR, ">&FILE" || die "Cannot redirect STDOUT";
print STDOUT "A\n";
print STDERR "B\n";
}
print STDOUT "C\n";
print STDERR "D\n";
|
|
#7
|
|||
|
|||
|
Quote:
C D and the contents of log.txt provided B A Why, is the order of the log file in reverse eventhough the order of the print commands is A and then B. Also I did a chmod -w on the current directory and tried your snippet. I was either expecting to see "Cannot write to log file" on the console, however the only output that I got was C D As always your feedback is greatly appreciated. Thanks. |
|||
| Google The UNIX and Linux Forums |