This is a creation in Article, where the information may have evolved or changed.
A lot of time to learn to stand on the shoulders of giants, the use of other existing things must be used, as long as the open source legal
Go call other C library, generally two ways, 1, to see if there is an interface, the use of CGO way to write; 2. Execute directly with the command line, provided that the C library must be called to be installed and run on the machine
To efficiently process GIF files, use the Gifsicle tool
http://download.csdn.net/detail/u010026901/7711469
Redirection conforms to > Error in code, so implementing redirection in code instead of 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)
}