Most of the time, you must learn to stand on the shoulders of giants and use other people's existing things as long as they are open-source and legal.
Go calls other C libraries in two ways: 1. Check whether an interface exists and write it in CGO mode; 2. run the command line directly. The C library that must be called has been installed and run on this machine.
Gifsicle is used to efficiently process GIF files.
Http://download.csdn.net/detail/u010026901/7711469
Redirection compliance> errors occur in the code, so implementing redirection in the Code replaces command line redirection.
Package main
Import (
// "Encoding/JSON"
// "FMT"
"Log"
"OS"
"OS/exec"
)
Func main (){
F, _: = OS. Create ("out ")
CMD: = exec. Command ("Echo", "-n", '{"name": "Bob", "Age": 32 }')
Cmd. stdout = f
// Stdout, err: = cmd. stdoutpipe ()
// If Err! = Nil {
// Log. Fatal (ERR)
//}
If err: = cmd. Start (); Err! = Nil {
Log. Fatal (ERR)
}
// Var person struct {
// Name string
// Age int
//}
//
// If err: = JSON. newdecoder (stdout). Decode (& person); Err! = Nil {
// Log. Fatal (ERR)
//}
If err: = cmd. Wait (); Err! = Nil {
Log. Fatal (ERR)
}
// FMT. printf ("% s is % d years old \ n", person. Name, person. Age)
}