I currently run an background process started by a deamon process. It has no terminal and works fine as it doesn't have any screen i/o. It is started via a shell script which I can change. The shell script inherit the daemon's environment, set up additional environment variables and finally starts the program via
exec $PROG arg1 "arg 2" 1>&2.
For running this in "debug mode" screen i/o is necessary (curses mode).
What I've tried so far:
exec screen -dmS FIXME $PROG arg1 "arg 2"results in a not starting program with the error message "invalid file descriptor"
exec $PROG arg1 "arg 2" 1>/dev/pts/5results in a starting program, all output can be seen on /dev/pts/5, of course input isn't possible
exec $PROG arg1 "arg 2" 1>/dev/pts/5 <namedpiperesults in a starting program, all output can be seen on /dev/pts/5, takes input via
echo stuff > namedpipefrom another session but this cannot be used as all function keys needs to be usable.
The "obvious" solution I thought of (but got not working):
- start a screen in another console
screen -dmS "FIXME"
- let the background process use this screen session via
exec screen -S "FIXME" -X stuff "$PROG arg1 \"arg 2\" "(newline is needed, it emulates pressing the Enter key)
- attach to the screen via
screen -r "FIXME"(reattaching works)
Problem here: This only sends the single command to the session, which doesn't work as the complete environment is missing (starting with the current directory, going on with all environment vars). [Edit: posted a possible solution hack as answer (the original question is still unanswered)]
Question: Is it possible to start the background process via screen utility? (Best option would be if the new screen session is started from the background process [problem here: this process has no console at all] and to simply reattach from another window.
If this isn't possible: Are there any other workarounds?