Golang os/exec.Cmd.CombinedOutput() function example
package os
Golang os/exec.Cmd.CombinedOutput() function usage example
package main
import (
"fmt"
"os/exec"
"strings"
)
func main() {
cmd := exec.Command("/bin/echo", "Hello World!")
// Join the output but without error yet
fmt.Printf("Output : %s \n", strings.Join(cmd.Args, " "))
//output, err := cmd.CombinedOutput() // combine the output with standard error
_, err := cmd.CombinedOutput() // combine the output with standard error
fmt.Printf("Combined output : %s \n", err)
}
Sample output :
Output : /bin/echo Hello World!
Combined output : fork/exec /bin/echo: not implemented on Native Client
Reference :
Advertisement
Something interesting
Tutorials
+14k Golang : Google Drive API upload and rename example
+8.5k Golang : How to check if input string is a word?
+52.6k Golang : How to get struct field and value by name
+17.6k Golang : delete and modify XML file content
+7.7k Golang : Error reading timestamp with GORM or SQL driver
+5.7k List of Golang XML tutorials
+9.7k PHP : Get coordinates latitude/longitude from string
+6.3k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+14k Golang : concatenate(combine) strings
+25.6k Golang : convert rune to integer value
+11.7k Golang : How to detect a server/machine network interface capabilities?
+20.7k Android Studio : AlertDialog and EditText to get user string input example