How to know a executable has finished his task

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • electroon
    New Member
    • Jan 2008
    • 8

    How to know a executable has finished his task

    Hi frnds,

    I want to know is there a way by which we can know that a C++ executable has finished its job in shell script.

    My task is as follows:

    1.Shell script calls a executable

    2.Executable executes and performs its job of generating some reports.

    Now i want my shell script to detect this that is C++ executable has completed its job so that shell script can send the reports as attachement.

    Please help me urgently on this
  • arne
    Recognized Expert Contributor
    • Oct 2006
    • 315

    #2
    Originally posted by electroon
    Hi frnds,

    I want to know is there a way by which we can know that a C++ executable has finished its job in shell script.

    My task is as follows:

    1.Shell script calls a executable

    2.Executable executes and performs its job of generating some reports.

    Now i want my shell script to detect this that is C++ executable has completed its job so that shell script can send the reports as attachement.

    Please help me urgently on this
    If the executable is not started in the background (or detaches itself from the shell or execves some other programs), the shell will not continue until the executable has returned. So, you should be able to simply do the mail transfer as the next command after the invocation of the executable.

    Let me know if I missed the point here :)

    arne

    Comment

    • bykwzpz
      New Member
      • Jan 2008
      • 12

      #3
      I agree - unless the executable fails. You might consider using the return code to determine the success or failure of the process. Most processes in UNIX return zero (0) as success and I will continue assuming yours does too.

      The shell script would look something like this:

      Code:
      your_c++_executable || {
           error_handling_procedure
           exit 1
           }
      
      procedure_to_get_ reports
      The ' || ' (or) is saying essentially: do the c++ process OR error out and exit. If the c++ process is successful (and returns 0), the shell would proceed to get reports. Hope this sheds additional light on the subject for you.

      Comment

      Working...