--wait to run a command synchronously — output streams to your terminal and the CLI exits with the process exit code:12oc exec sb-abc123 --wait -- echo "Hello, World!" oc exec sb-abc123 --wait -- npm run build
--wait, oc exec creates an exec session and prints the session ID with attach instructions. This is useful for long-running commands:12oc exec sb-abc123 -- node server.js # → Session es-xyz created. Attach with: oc exec attach sb-abc es-xyz
12oc exec sb-abc123 --wait --cwd /app --env NODE_ENV=production -- npm run build oc exec sb-abc123 --wait --env API_KEY=xxx --env DEBUG=true -- ./run.sh
--timeout (in seconds). Default is 0 (no timeout). When exceeded, the command is killed:1oc exec sb-abc123 --wait --timeout 30 -- npm test
oc exec (without --wait) creates a session for long-running commands. The command keeps running even after you disconnect:12oc exec sb-abc123 -- python train.py # Session es-abc created
--json with --wait for scripting:123RESULT=$(oc exec sb-abc123 --json --wait -- node -e 'console.log("hello")') echo $RESULT | jq '.stdout' # "hello\n" echo $RESULT | jq '.exitCode' # 0
123456# List active sessions oc exec list sb-abc123 # Kill a session oc exec kill sb-abc123 es-xyz oc exec kill sb-abc123 es-xyz --signal 15 # SIGTERM
oc exec attach exists as a command but is not yet implemented. It prints guidance to use the SDK or a WebSocket client. Use oc exec list and oc exec kill to manage sessions from the CLI.| Use Case | Command |
| Single command, capture output | oc exec --wait |
| Scripting and automation | oc exec --wait --json |
| Long-running background process | oc exec (no --wait) |
| Interactive development, debugging | oc shell |