Spaces:
Sleeping
Sleeping
| """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}") | |