#endif
-enum { EXEC_NOERROR = 0, EXEC_SYSTEMFAILED };
+enum { EXEC_SYNCHRONOUS = -2, EXEC_NOERROR = 0, EXEC_SYSTEMFAILED,
+ EXEC_CHILDFAILED };
static const char *cmdmsg_values[] =
- { "", "Execution of child process impossible" };
+ { "",
+ "Termination status of the command-language interpreter cannot be obtained",
+ "Execution of child process impossible" };
{
if (cmdstat)
*cmdstat = value;
- else if (value != 0)
+ else if (value > EXEC_NOERROR)
runtime_error ("Could not execute command line");
}
/* Asynchronous execution. */
pid_t pid;
- set_cmdstat (cmdstat, 0);
+ set_cmdstat (cmdstat, EXEC_NOERROR);
if ((pid = fork()) < 0)
- set_cmdstat (cmdstat, EXEC_SYSTEMFAILED);
+ set_cmdstat (cmdstat, EXEC_CHILDFAILED);
else if (pid == 0)
{
/* Child process. */
/* Synchronous execution. */
int res = system (cmd);
- if (!wait)
- set_cmdstat (cmdstat, -2);
- else if (res == -1)
+ if (res == -1)
set_cmdstat (cmdstat, EXEC_SYSTEMFAILED);
+ else if (!wait)
+ set_cmdstat (cmdstat, EXEC_SYNCHRONOUS);
else
+ set_cmdstat (cmdstat, EXEC_NOERROR);
+
+ if (res != -1)
{
- set_cmdstat (cmdstat, 0);
#if defined(WEXITSTATUS) && defined(WIFEXITED)
*exitstat = WIFEXITED(res) ? WEXITSTATUS(res) : res;
#else
}
/* Now copy back to the Fortran string if needed. */
- if (cmdstat && *cmdstat > 0)
+ if (cmdstat && *cmdstat > EXEC_NOERROR)
{
if (cmdmsg)
fstrcpy (cmdmsg, cmdmsg_len, cmdmsg_values[*cmdstat],