Skip to content

Fix crash when running with nohup on Linux due to closed stdin#158

Draft
Copilot wants to merge 2 commits into
masterfrom
copilot/allow-nohup-background-running
Draft

Fix crash when running with nohup on Linux due to closed stdin#158
Copilot wants to merge 2 commits into
masterfrom
copilot/allow-nohup-background-running

Conversation

Copy link
Copy Markdown

Copilot AI commented Nov 15, 2025

When running with nohup or in detached mode on Linux, the application crashes with IOException: Bad file descriptor because stdin is redirected to /dev/null and closed, causing Console.Read() to throw.

Changes

  • Command.cs: Wrap Console.Read() in try-catch for IOException when input is redirected
    • Treat IOException as equivalent to -1 (no input available)
    • Continues execution loop with delay instead of propagating exception
// Before
if (Console.IsInputRedirected)
{
    int keyPressed = Console.Read();  // Throws IOException on closed stdin
    ...
}

// After
if (Console.IsInputRedirected)
{
    int keyPressed;
    try
    {
        keyPressed = Console.Read();
    }
    catch (IOException)
    {
        // stdin closed (e.g., nohup, systemd service)
        keyPressed = -1;
    }
    ...
}

This allows the application to run unattended in background/detached scenarios while maintaining normal console input behavior when stdin is available.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: ./OpenDirectoryDownloader --url REDACTED --quit (dns block)
  • www.example.com
    • Triggering command: ./OpenDirectoryDownloader --url REDACTED --quit (dns block)
  • www.falsedoor.com
    • Triggering command: ./OpenDirectoryDownloader --url REDACTED --quit (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Allow nohup background running</issue_title>
<issue_description>Hello there,

Currently, on Linux, if you try to run ODD in an unattended way, for instance with nohup, it does not work at all, the following message is returned:

Console input is redirect, maybe it is run inside another host. This could mean that no input will be send/processed.
2025-01-10 20:01:43.705 [WRN] Console input is redirect, maybe it is run inside another host. This could mean that no input will be send/processed.
2025-01-10 20:01:43.751 [ERR] Error processing action
System.UnauthorizedAccessException: Access to the path is denied.
 ---> System.IO.IOException: Bad file descriptor
   --- End of inner exception stack trace ---
   at Interop.ThrowExceptionForIoErrno(ErrorInfo, String, Boolean)
   at Interop.CheckIo(Int64, String , Boolean )
   at Interop.CheckIo(Int32, String , Boolean )
   at System.ConsolePal.Read(SafeFileHandle, Span`1)
   at System.ConsolePal.UnixConsoleStream.Read(Span`1)
   at System.IO.ConsoleStream.Read(Byte[], Int32, Int32)
   at System.IO.StreamReader.ReadBuffer()
   at System.IO.StreamReader.Read()
   at System.IO.SyncTextReader.Read()
   at System.Console.Read()
   at OpenDirectoryDownloader.Command.ProcessConsoleInput(OpenDirectoryIndexer openDirectoryIndexer)
Unhandled exception. System.UnauthorizedAccessException: Access to the path is denied.
 ---> System.IO.IOException: Bad file descriptor
   --- End of inner exception stack trace ---
   at Interop.ThrowExceptionForIoErrno(ErrorInfo, String, Boolean)
   at Interop.CheckIo(Int64, String , Boolean )
   at Interop.CheckIo(Int32, String , Boolean )
   at System.ConsolePal.Read(SafeFileHandle, Span`1)
   at System.ConsolePal.UnixConsoleStream.Read(Span`1)
   at System.IO.ConsoleStream.Read(Byte[], Int32, Int32)
   at System.IO.StreamReader.ReadBuffer()
   at System.IO.StreamReader.Read()
   at System.IO.SyncTextReader.Read()
   at System.Console.Read()
   at OpenDirectoryDownloader.Command.ProcessConsoleInput(OpenDirectoryIndexer openDirectoryIndexer)
   at OpenDirectoryDownloader.Program.Main(String[] args)
   at OpenDirectoryDownloader.Program.<Main>(String[] args)

Could you allow such capacity ?

Cheers!</issue_description>

Comments on the Issue (you are @copilot in this section)

@KoalaBear84 Hi,

I have never heard of this. How do you start/use it? What is the purpose?</comment_new>
<comment_new>@KoalaBear84
I've tried reproducing it, but I can't :)

koalabear@DESKTOP-XX:~$ nohup ./OpenDirectoryDownloader --url https://www.falsedoor.com/txt/ &
[1] 27642
koalabear@DESKTOP-XX:~$ nohup: ignoring input and appending output to 'nohup.out'
koalabear@DESKTOP-XX:~$

koalabear@DESKTOP-XXX:~$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.2 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

What can I try next?</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Nov 15, 2025
…osed

Co-authored-by: KoalaBear84 <5886900+KoalaBear84@users.noreply.github.com>
Copilot AI changed the title [WIP] Allow nohup for unattended ODD execution Fix crash when running with nohup on Linux due to closed stdin Nov 15, 2025
Copilot AI requested a review from KoalaBear84 November 15, 2025 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow nohup background running

2 participants