File size: 701 Bytes
88a1dd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Run from a regular terminal (not inside Claude Code) to capture stream-json output."""

import subprocess
import sys

cmd = [
    "claude",
    "--output-format", "stream-json", "--verbose",
    "-p", "Say hello in one sentence",
]

print(f"Running: {' '.join(cmd)}\n", file=sys.stderr)

proc = subprocess.Popen(
    cmd,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    text=True,
    bufsize=1,
)

print("=== stdout lines ===")
while True:
    line = proc.stdout.readline()
    if not line and proc.poll() is not None:
        break
    print(repr(line))

print(f"\n=== exit code: {proc.returncode} ===")
stderr = proc.stderr.read()
if stderr:
    print(f"\n=== stderr ===\n{stderr}")