Go calls other C libraries. If the command line method is used, the redirection output is not supported. If the SMP protocol is not opened, messages are sent to the other party, and no response is returned.

Source: Internet
Author: User

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)
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.