On 2024-05-07 10:24:49, Marek Lukács <ma...@lukacs.cz> spake thus:
Is it possible to capture last exit status code after screen finished (eg.
environment variable $SCREEN_EXIT_CODE), or copy last status code to screen'
s exit status code, so I can check it using $? ?

Hi Marek,

I'm not aware of any way to cause a program's exit status to be reflected in the exit status of 'screen' itself. But even if that were possible, it would probably be less reliable than you would want, because the ability to detect an error by the status code would then depend on the order in which subprocesses exit within screen.

E.g., if a given screen session runs two subprocesses, and the first one exits with a non-zero (error) status and the other exits with a zero (success) status a moment later, then having the "last exit status code" reflected in the exit status of the screen process would still mask the error of the subprocess that failed.

A different approach would be to use wrapper scripts that write their exit statuses to some well-known location in the file system. Rather than have screen launch your program(s) directly, it would instead launch a corresponding wrapper script:

    #!/bin/sh
    /path/to/some/program "$@"
    printf '%s\n' "$?" >> /path/to/estat

To make that approach as reliable as possible, it would be best to create '/path/to/estat' prior to launching the subprocess in the screen session. That would allow you to detect "file system full" or situations in which there are inadequate persmissions to write the exit status file.

Best regards,
-Al

--
a l a n   d.   s a l e w s k i
ads@salewski.email
salew...@att.net
https://github.com/salewski

Reply via email to