Toon posts:

[PERL] Returncode opvangen van een extern programma.

Pagina: 1
Acties:

Verwijderd

Topicstarter
Weet er iemand hoe ik de returncode van een extern programma opvang in een variable?
Executen zelf gaat gewoon door bv. $output=`./naamvanprog`; waarna de output van het programma in $output zit. Maar ik zou niet weten hoe ik de returncode van dat programma kan krijgen...

  • JayTaph
  • Registratie: Oktober 1999
  • Laatst online: 28-11-2025

JayTaph

Portability is for canoes.

man perlvar:

code:
1
2
3
4
5
6
7
8
9
10
 $?      The status returned by the last pipe close, back­
               tick (``) command, successful call to wait() or
               waitpid(), or from the system() operator.  This is
               just the 16-bit status word returned by the wait()
               system call (or else is made up to look like it).
               Thus, the exit value of the subprocess is really
               ("$? >> 8"), and "$? & 127" gives which signal, if
               any, the process died from, and "$? & 128" reports
               whether there was a core dump.  (Mnemonic: similar
               to sh and ksh.)

Yo dawg, I heard you like posts so I posted below your post so you can post again.


  • unclero
  • Registratie: Juni 2001
  • Laatst online: 08:20

unclero

MB EQA ftw \o/

Probeer:
code:
1
my $returncode = system "./programma";


Ook kan dacht ik:
code:
1
2
3
my @bla = ("cp","argv 1","argv 2");
my $returncode = syscall @bla;
if($returncode  == -1) { die "error programma: $!\n" }

[ Voor 0% gewijzigd door unclero op 07-11-2002 13:51 . Reden: oepsie.. vergeet te nesten ]

Quelle chimère est-ce donc que l'homme? Quelle nouveauté, quel monstre, quel chaos, quel sujet de contradiction, quel prodige!


  • muba
  • Registratie: April 2002
  • Laatst online: 19-10-2013

muba

Prince of Persia!

Hrrmz... dit is voor mij ook nieuw en wellicht wel handig om te weten... heb ff om te testen 2 scriptjes geschreven:

Perl:
1
2
3
# errorlevelcaller.pl
`perl errorlevel.pl`;
print "$?\n";


Perl:
1
2
# errorlevel.pl
exit 1;


Ja, echt technische hoogstandjes, ik weet het... Maar dit is mijn output van errorlevelcaller.pl:
256

1? 256? Huu? Waar is de missing link?


Nevermind, ik moet eens niet denken na een halve tekst gelezen te hebben, de hele tekst te kennen :D

Het is me alleen nog nooit fatsoenlijk gelukt om >> en << te begrijpen. & en | begrijp ik wel maar >> snap ik echt totaal niet, zou iemand me dat willen uitleggen in begrijpelijke taal? :'( :*)

Reporter: Mister Gandhi, what do you think of western civilisation?
Gandhi: I think it would be a good idea