I know screen -dmS mysession command to start a screen, launch a command and detach. When we need to redirect the stdout to a file, this works: (see How to run a program in a screen, redirect all output to a file and detach)
screen -dmS mysession bash -c 'ls > test.txt' # simple example
However at the end, the screen session doesn't stay, we cannot do screen -r mysession, it doesn't exist anymore in screen -ls.
Question: in a one-liner, how to start a screen session, launch a command, detach, redirect stdout to a file (like > test.txt) but don't automatically exit the screen session when finished?
Linked question: How to prevent "screen -dmS sessionName program.sh" from disappearing after program.sh finishes?