How to exit our application - elips-studio

How to exit from my application? How to add, option and exit option in my application?

call exit() to exit our application...

Related

catching error code of background task

I have a python script, in my raspberry, that runs in a infinite loop. I want to catch it's exit code in case it stops. I made a script named run like this:
#!/bin/bash
~/bin/script.py &
wait $! && echo "script exited with code $?" >> ~/bin/log/script.log &
but when I run it i get the following error:
~/bin/run: line 3: wait: pid 2728 is not a child of this shell
Can anyone give me some hint of a solution?
You are pushing your (single) script to the background and then do a blocking wait. I think, this is unnecessary. You may just write:
!/bin/bash
~/bin/script.py
echo "script exited with code $?" >> ~/bin/log/script.log

Why does a non-interactive batch script think I've pressed control-C?

So my batch script is ticking along nicely when suddenly this appears in the output log:
21:27:13.99 c:\apps\w7lab-scripting>some-command
Error 3221225786
^CTerminate batch job (Y/N)?
and the script stops dead.
The batch script is running in session zero, so I know it didn't receive a real control-C, and none of my code calls GenerateConsoleCtrlEvent so that can't be it. The only clue is that some-command was communicating with an interactive application at the time, and that application's console received a control-C. The expected behaviour was for some-command to display the other application's exit code, then exit with the same code. The batch script would have dealt with the error appropriately, if it hadn't stopped dead.
What's going on here?
The magic here is in exit code 3221225786, aka 0xC000013A or STATUS_CONTROL_C_EXIT.
The interactive application received a control-C, and didn't catch it, so as expected, it was aborted with STATUS_CONTROL_C_EXIT. The some-command application correctly reported this as the remote application's exit code, and passed it back to the batch script.
What I hadn't realized was that cmd.exe detects control-C in a batch script in exactly this way, by checking whether a child process returns STATUS_CONTROL_C_EXIT. So by returning this error code I was inadvertently stopping the batch script.
This can be demonstrated with a simple batch script:
cmd /c exit 3221225786
echo hello
which, when run, produces
C:\working\test>cmd /c exit 3221225786
^CTerminate batch job (Y/N)?
Alternatively, it is possible to terminate batch session using commands that provoke brutal batch end (from https://superuser.com/a/805637), any of the following (attempting to feed STDERR to STDIN breaks):
cd invalidPath 2>&0
vol x 2>&0
move nonExistentFile 2>&0
set nonExistentVariable 2>&0
dir nonExistentFile 2>&0
So, a subroutine could be:
:SubSelfTerminate
cd invalidPath 2>&0
exit /b 0
which would be called from Main batch as:
call :SubSelfTerminate
Note: "exit /b 0" in subroutine is useless as will always be ignore it is used but mark the end the subroutine.

what is the difference between exit and exit! in ruby?

What is the difference between exit and exit! in ruby?
Couple things:
Exit handlers get run in the "exit" form but not "exit!". This means any code that is assigned to "clean-up" won't get run using "exit!"
The "exit status" is default set to false in the "exit!" form, whereas it is true in the "exit" form. The "exit status" is a message to the operating system about the program that is stopping execution.
they are both Kernel methods: http://www.ruby-doc.org/core/classes/Kernel.html

Process Exit Code When Process is Killed Forcibly

When we kill a process in Windows with Task Manager End Process command, will the process still return an exit code? And if so, what exit code it returns? Thanks
In general, a process is terminated using TerminateProcess. The exit code is passed as a parameter to this method.
In the case of the task manager, the exit code is set to 1, but I don't know if it's documented anywhere.
Yes, it will return non-zero return code which will be wrapped in %ERRORLEVEL% variable.

Using Until to Restart a Process when it dies

I read this Question:
"How do I write a bash script to restart a process if it dies".
A solution is to:
until myserver; do
echo "Server 'myserver' crashed with exit code $?. Respawning.." >&2
sleep 1
done
Will this work for Tomcat/Jetty processes that are started from a script?
Do I test the success with "kill" to see if the process restarts?
If the script returns exit codes as specified in the answer at that link, then it should work. If you go back and read that answer again, it implies that you should not use kill. Using until will test for startup because a failed startup should return a non-zero exit code. Replace "myserver" with the name of your script.
Your script can have traps that handle various signals and other conditions. Those trap handlers can set appropriate exit codes.
Here is a demo. The subshell (echo "running 'dummy'"; sleep 2; exit $result) is a standin for your script:
result=0
until (echo "running 'dummy'"; sleep 2; exit $result)
do
echo "Server 'dummy' crashed with exit code $?. Respawning.." >&2
sleep 1
done
Try it with a failing "dummy" by setting result=1 and running the until loop again.
while true
do
if pgrep jett[y] 1>/dev/null;then
sleep 1
else
# restart your program here
fi
done

Resources