Created
June 4, 2025 13:29
-
-
Save vinitkumar/68bdcf335824499c10452e60a8e2f060 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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