Issue
One way to wait for a RETURN keypress is to call std::ignore(). However, when I use nohup std::ignore() always returns immediately. Does there exist an alternative way to wait for a keypress, or just return that will work with nohup?
Solution
When you use nohup
to run a command, it connects the standard input of your command to /dev/null so there's no way to wait for any kind of keypress.
When you attempt a read from /dev/null, it automatically responds with EOF.
I guess this could be checked using the following code (untested):
#include <unistd.h>
...
if (isatty(fileno(stdin))) ...
This should work, as the standard guarantees that std::cin
is associated with stdin.
Answered By - IanM_Matrix1 Answer Checked By - Willingham (WPSolving Volunteer)