[32867] in Perl-Users-Digest
Perl-Users Digest, Issue: 4145 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 22 21:09:35 2014
Date: Sat, 22 Feb 2014 18:09:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 22 Feb 2014 Volume: 11 Number: 4145
Today's topics:
Re: How do I get "system" to report the correct failure <derykus@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 22 Feb 2014 17:27:08 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: How do I get "system" to report the correct failure message?
Message-Id: <c8250516-7f9c-4274-a8df-a2e4e5d298c4@googlegroups.com>
On Friday, February 21, 2014 4:19:55 PM UTC-8, Ben Morrow wrote:
> Quoth laredotornado@zipmail.com:
> ....
>
> You are checking $? and then printing $!. Properly speaking you need to check both:
>
> use Fcntl qw/:sys_wait_h/;
> my $st = system (...);
> if ($st == -1) {
> die "failed to run jboss-cli: $!";
> }
> elsif ($st != 0) {
> if (WIFEXITED($?)) {
> die sprintf "jboss-cli exited with status %i",
> WEXITSTATUS($?);
> }
> elsif (WIFSIGNALED($?)) {
> die sprintf "jboss-cli was killed with signal %i",
> WTERMSIG($?);
> }
> else {
> # shouldn't happen
> die "jboss-cli failed: $?";
> }
> }
>
> On systems which use non-standard return values from wait(2) you may
> need to replace $? with ${^CHILD_ERROR_NATIVE}, though IIRC this is not consistent across perl versions.
> > }
> > However, what Perl reports is "Failed to deploy /tmp/my.war:
> > Inappropriate ioctl for device" and when I run the command in a shell,
> > the actual error message is "{"JBAS014653: Composite operation failed
> > and was rolled back. Steps that failed:" => {"Operation step-2" =>
> > {"JBAS014671: Failed services" =>
> > {"jboss.web.deployment.default-host./my" =>
> > "org.jboss.msc.service.StartException in service
> > jboss.web.deployment.default-host./my: JBAS018040: Failed to start
> > context"},"JBAS014771: Services with missing/unavailable dependencies"
> > => ["jboss.deployment.unit.\"my.war\".jboss.security.jacc
> > Missing[JBAS014861: <one or more transitive dependencies>]"]}}}".
> >
> > Any ideas how I can output the correct error message?
>
> Does the command print this to stderr (or, indeed, stdout)? I would
> expect this to be visible when you run the command via system, given
> that you haven't redirected either. What matters is to make sure your
> Perl program also realises something went wrong.
>
Or, maybe outputting stdout/stderr will convey enough:
use IPC::Run qw/run/;
@cmd = ("$jbossHome/bin/jboss-cli.sh", "--file=$file");
run( \@cmd, '>&', \$out_and_err )
or die "run: $? status=$out_and_err";
...
--
Charles DeRykus
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 4145
***************************************