× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



If all else fails, and
   you're using ILE, and
   you don't mind binding your CL with an ILE C module, and
   I can trust the API docs, then
   the following might work:

Write an ILE C wrapper function that uses the 'spawn process with path'
API to launch your C PGM and the 'wait for specific child process' API to
poll for its exit status.  Basically you'd use spawnp to launch the app
and get its process ID, then call waitpid with the process ID until the
WIFEXITED macro returns true, then use the WEXITSTATUS macro to get the
return value from main().  Presumably you could then return that value
from your wrapper function to a CALLPRC line in your CL program.

#include <spawn.h>

pid_t spawnp(const char *file,
             const int fd_count,
             const int fd_map[],
             const struct inheritance *inherit,
             char * const argv[],
             char * const envp[]);

#include <sys/types.h>
#include <sys/wait.h>

pid_t waitpid(pid_t pid, int *stat_loc, int options);

Related doc verbage:

"The status referenced by the stat_loc argument is interpreted using
macros defined in the <sys/wait.h> header file. The macros use an argument
stat_val, which is the integer value pointed to by stat_loc. When
waitpid() returns with a valid process ID (pid), the macros analyze the
status referenced by the stat_loc argument. The macros are as follows:

WIFEXITED(stat_val) Evaluates to a nonzero value if the status was
returned for a child process that ended normally.

WEXITSTATUS(stat_val) If the value of the WIFEXITED(stat_val) is nonzero,
evaluates to the low-order 8 bits of the status argument that the child
process passed to exit(), or to the value the child process returned from
main()."

Source: v5r3 UNIX-type Process Related APIs

Hope this helps-

-Jared

On Thu, 16 Sep 2004, Mark Phippard wrote:

> I am calling a C program from CL via the CALL command.  The C function
> returns an error number like 0 or 1 for success or failure.  Is there some
> way to retrieve this value from a CL program?  I can run the program via
> QSH and see the return code, but I would prefer to just use CALL for this.
>  I assume there is no way to use CALLPRC when you need to run the main()
> function in a C *PGM?


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.