Fix file argument detection when stdin is /dev/null#414
Merged
Conversation
Fixes antonmedv#398 where fx incorrectly treats file paths as code arguments when run in launch agents or other non-TTY contexts with stdin redirected to /dev/null. Root cause: The original code only checked isatty(stdin) to decide between file mode and pipe mode. In launch agents, stdin is not a TTY but also not a pipe (often /dev/null), causing fx to incorrectly assume piped input and treat the file path as JS code. Solution: Check if stdin is an actual input stream (pipe or regular file) vs a character device (/dev/null, /dev/tty). Use os.ModeCharDevice to distinguish: - Character devices (TTY, /dev/null) → file mode - Pipes and regular files → pipe mode This preserves all existing behavior while fixing the launch agent case.
antonmedv
approved these changes
May 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
fxruns in non-TTY contexts (like macOS LaunchAgents) where stdin is redirected from/dev/null, it incorrectly assumes piped input. It then evaluates the first argument (a file path) as JavaScript, resulting in aSyntaxError(parsing/tmp/package.jsonas a RegExp literal/tmp/with flagspackage.json).Example:
Error:
Previously, we relied solely on
isatty(stdin). This adds a device-type check usingos.ModeCharDevice: character devices (TTY,/dev/null) route to file mode, while non-character devices (pipes, regular files) route to stdin-input mode.Fixes #398