Skip to content

Instantly share code, notes, and snippets.

@vinitkumar
Created June 4, 2025 13:29
Show Gist options
  • Save vinitkumar/68bdcf335824499c10452e60a8e2f060 to your computer and use it in GitHub Desktop.
Save vinitkumar/68bdcf335824499c10452e60a8e2f060 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"bytes"
"io"
"log"
)
func main() {
// Simulated command output
// First line = session ID, others = output
output := "session-abc123\nLine 1\nLine 2\n"
// Use a bytes.Reader to simulate command output
reader := bytes.NewReader([]byte(output))
processOutput(reader)
}
func processOutput(reader io.Reader) {
var sessionID string
var receivedSessionID bool
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
line := scanner.Text()
if !receivedSessionID {
sessionID = line
log.Printf("Received session ID: %s", sessionID)
receivedSessionID = true
continue
}
log.Printf("[%s] Received output: %s", sessionID, line)
}
if err := scanner.Err(); err != nil {
log.Fatalf("Error reading command output: %v", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment