tags:

views:

52

answers:

3

I am creating an interpreter for my extension to HQ9+, which has the following extra command called V:

V: Interpretes the code as Lua, Brainfuck, INTERCAL, Ruby, ShellScript, Perl, Python, PHP in that order, and if even one error has occoured, run the HQ9+-ABC code again

most of them have libraries, BF and INTERCAL can be interpreted without a library, but the problem lies in ShellScript. How can I run a shellscript from my C++ application ( =the HQ9+-ABC interpreter) and when it's done, get the error code (0 = succeded, all others = failed)? So something like this:

system(".tempshellscript738319939474");
if(errcode != 0) { (rerun code); }

can anyone help me? Thanks

+2  A: 

From man system(3):

    RETURN VALUE
       The value returned is -1 on error (e.g. fork failed),  and  the  return
       status  of  the command otherwise.  This latter return status is in the
       format specified in wait(2).  Thus, the exit code of the  command  will
       be  WEXITSTATUS(status).   In  case  /bin/sh could not be executed, the
       exit status will be that of a command that does exit(127).
Greg Hewgill
+1  A: 

system() returns a code depending on the success or failure of whatever you called.

http://www.cplusplus.com/reference/clibrary/cstdlib/system

Christian Jonassen
A: 

I remember execve call working for shell scripts that had #! interpreter in their first line for an assignment at university. If you are using system, consider trying execve as well. wait on the pid of the script could help receiving the exit status.

vpit3833