Skip to content

gbrain put <slug> fails on Windows with ENOENT: /dev/stdin #1362

@ecat2010

Description

@ecat2010

Bug Description

gbrain put <slug> fails on Windows with ENOENT: /dev/stdin error.

Steps to Reproduce

  1. On Windows, run: echo "some content" | gbrain put test-slug
  2. Observe error

Expected Behavior

gbrain put should read stdin content and create/update the page successfully on all platforms.

Actual Behavior

Error: ENOENT: no such file or directory, open '/dev/stdin'

Root Cause

In src/cli.ts, stdin is read via:

const stdinContent = readFileSync('/dev/stdin', 'utf-8');

/dev/stdin does not exist on Windows. This path is Unix-only.

Proposed Fix

Wrap the stdin read in a try/catch with a Windows fallback using readSync on fd 0:

// In src/cli.ts, replace:
const stdinContent = readFileSync('/dev/stdin', 'utf-8');

// With:
let stdinContent: string;
try {
  stdinContent = readFileSync('/dev/stdin', 'utf-8');
} catch {
  // Windows fallback: read from stdin fd directly
  const fd = 0;
  const chunks: Buffer[] = [];
  const buf = Buffer.alloc(65536);
  let nread: number;
  while ((nread = readSync(fd, buf, 0, buf.length, null)) > 0) {
    chunks.push(buf.slice(0, nread));
  }
  stdinContent = Buffer.concat(chunks).toString('utf-8');
}

Also need to add readSync to the import:

import { readFileSync, readSync } from 'fs';

Environment

  • OS: Windows 11
  • gbrain version: 0.39.0
  • Runtime: Bun

Additional Context

This affects all gbrain put operations that pipe content via stdin on Windows. The --file parameter workaround (using a temp file) works, but stdin piping is a common UX pattern that should work cross-platform.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions