comp.lang.ada
 help / color / mirror / Atom feed
* Return value of system call (newbie question)
@ 2001-05-16 10:08 Torbjörn Karfunkel
  2001-05-16 15:56 ` Mark Biggar
  2001-05-16 16:08 ` Jeffrey Carter
  0 siblings, 2 replies; 3+ messages in thread
From: Torbjörn Karfunkel @ 2001-05-16 10:08 UTC (permalink / raw)
  To: comp.lang.ada

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








^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-05-16 16:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-16 10:08 Return value of system call (newbie question) Torbjörn Karfunkel
2001-05-16 15:56 ` Mark Biggar
2001-05-16 16:08 ` Jeffrey Carter

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