comp.lang.ada
 help / color / mirror / Atom feed
From: "Torbjörn Karfunkel" <toka@prover.com>
To: comp.lang.ada@ada.eu.org
Subject: Return value of system call (newbie question)
Date: Wed, 16 May 2001 12:08:54 +0200
Date: 2001-05-16T12:08:54+02:00	[thread overview]
Message-ID: <mailman.990008355.31624.comp.lang.ada@ada.eu.org> (raw)

I'm executing an external program from within an Ada program by using

   function OtterCall(Value : String) return Integer;
   pragma Import(C, OtterCall, "system");

The program that is called upon, Otter, is called with the syntax

otter <input-file> output-file

and the calls look like this (several calls to each are made)

         Result := OtterCall(Value =>
("/home/toka/otter/otter-3.0.6/source/otter " &
                                       "<
/home/toka/exjobb/model_checker/nyare/" &
                                       ("sat" &
Natural'Image(K)(2..Natural'Image(K)'Last) & ".in") &
                                       " >
/home/toka/exjobb/model_checker/nyare/" &
                                       ("satresult" &
Natural'Image(K)(2..Natural'Image(K)'Last) & ".oout")));

         Result := OtterCall(Value =>
("/home/toka/otter/otter-3.0.6/source/otter " &
                                       "<
/home/toka/exjobb/model_checker/nyare/" &
                                       ("taut" &
Natural'Image(K)(2..Natural'Image(K)'Last) & ".in") &
                                       " >
/home/toka/exjobb/model_checker/nyare/" &
                                       ("tautresult" &
Natural'Image(K)(2..Natural'Image(K)'Last) & ".oout")));

Two problems have arisen:
1) The first call to otter was executed normally and produced the
outfile satresult0.oout,
    but the second call, which I thought would produce the outfile
tautresult0.oout, produced
    an outfile named tautresult0.oout0.oout.
    It seems that some part of the Value string from the previous call
is appended to the end
    of the next.  I solved this problem by appending a sequence of
blanks to the end of the Value
    strings, but this seems unnecessary. Could anyone give an
explanation to this behavior?
2) The value of Result is 26624. The program executed, Otter, produces
exit codes, and I would
    like to get access to this exit code in some way instead of systems
return value. How is this
    accomplished? The manual on system says

RETURN VALUE
       The value returned is 127 if the execve() call for /bin/sh
fails,  -1  if
       there was another error and the return code of the command
otherwise.

       If  the  value of string is NULL, system() returns nonzero if the
shell is
       available, and zero if not.

       system() does not affect the wait status of any other children.

Grateful for assistance
/Torbj�rn Karfunkel








             reply	other threads:[~2001-05-16 10:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-16 10:08 Torbjörn Karfunkel [this message]
2001-05-16 15:56 ` Return value of system call (newbie question) Mark Biggar
2001-05-16 16:08 ` Jeffrey Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox