Go call other C library, if the command line, not support redirection output resolution; SMP protocol not open, send information to each other, no one responds

Source: Internet
Author: User
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)
}

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.