当前位置: 首页 > news >正文

营销网络建设四个阶段引擎优化seo怎么做

营销网络建设四个阶段,引擎优化seo怎么做,网站搭建博客,wordpress邮箱登录go语言将cmd stdout和stderr作为字符串返回而不是打印到控制台 1、直接打印到控制台 从 golang 应用程序中执行 bash 命令,现在 stdout 和 stderr 直接进入控制台: cmd.Stdout os.Stdout cmd.Stderr os.Stderrpackage mainimport ("fmt"…

go语言将cmd stdout和stderr作为字符串返回而不是打印到控制台

1、直接打印到控制台

从 golang 应用程序中执行 bash 命令,现在 stdout 和 stderr 直接进入控制台:

cmd.Stdout = os.Stdout 
cmd.Stderr = os.Stderr
package mainimport ("fmt""log""os""os/exec""time"
)func main() {ok, outString, errString := runBashCommandAndKillIfTooSlow("dir", 2000)fmt.Println("ok")fmt.Println(ok)fmt.Println("outString")fmt.Println(outString)fmt.Println("errString")fmt.Println(errString)
}/*run bash command and kill it if it works longer than "killInMilliSeconds" milliseconds
*/
func runBashCommandAndKillIfTooSlow(command string, killInMilliSeconds time.Duration) (okResult bool, stdout, stderr string) {fmt.Println("running bash command...")fmt.Println(command)// Linux// cmd := exec.Command("sh", "-c", command)// Windowscmd := exec.Command("cmd", "/C", command)cmd.Stdout = os.Stdout // cmd.Stdout -> stdoutcmd.Stderr = os.Stderr // cmd.Stderr -> stderrokResult = trueerr := cmd.Start()log.Printf("Waiting for command to finish...")done := make(chan error, 1)go func() {done <- cmd.Wait()}()select {case <-time.After(killInMilliSeconds * time.Millisecond):if err := cmd.Process.Kill(); err != nil {log.Fatal("failed to kill: ", err)okResult = false}// allow goroutine to exit<-donelog.Println("process killed")case err := <-done:if err != nil {log.Printf("process done with error = %v", err)okResult = false}}if err != nil {log.Fatal(err)okResult = false}return
}

如果 bash 命令太慢( killInMilliSeconds 参数),程序应该保持其终止 bash 命令的能力。

希望 stdout 和 stderr 作为字符串变量从 runBashCommandAndKillIfTooSlow 函数返回,而不立即打印到控

制台,如何实现。

2、不打印到控制台

将输出设置为 strings.Builder 或 bytes.Buffer:

var outbuf, errbuf strings.Builder // or bytes.Buffer
cmd.Stdout = &outbuf
cmd.Stderr = &errbuf

运行命令后,您可以通过调用 Builder.String() 获取字符串形式的标准输出和标准错误:

stdout := outbuf.String()
stderr := errbuf.String()
package mainimport ("fmt""log""os/exec""strings""time"
)func main() {ok, outString, errString := runBashCommandAndKillIfTooSlow("dir", 2000)fmt.Println("ok")fmt.Println(ok)fmt.Println("outString")fmt.Println(outString)fmt.Println("errString")fmt.Println(errString)
}/*run bash command and kill it if it works longer than "killInMilliSeconds" milliseconds
*/
func runBashCommandAndKillIfTooSlow(command string, killInMilliSeconds time.Duration) (okResult bool, stdout, stderr string) {fmt.Println("running bash command...")fmt.Println(command)// Linux// cmd := exec.Command("sh", "-c", command)// Windowscmd := exec.Command("cmd", "/C", command)var outBuf, errBuf strings.Builder // or bytes.Buffercmd.Stdout = &outBufcmd.Stderr = &errBufokResult = trueerr := cmd.Start()log.Printf("Waiting for command to finish...")done := make(chan error, 1)go func() {done <- cmd.Wait()}()select {case <-time.After(killInMilliSeconds * time.Millisecond):if err := cmd.Process.Kill(); err != nil {log.Fatal("failed to kill: ", err)okResult = false}// allow goroutine to exit<-donelog.Println("process killed")case err := <-done:if err != nil {log.Printf("process done with error = %v", err)okResult = false}}if err != nil {log.Fatal(err)okResult = false}stdout = outBuf.String()stderr = errBuf.String()return
}

文章转载自:
http://nisan.rymd.cn
http://actinograph.rymd.cn
http://archon.rymd.cn
http://expurgatorial.rymd.cn
http://sanhedrin.rymd.cn
http://obligatory.rymd.cn
http://runologist.rymd.cn
http://pueblo.rymd.cn
http://plagiotropic.rymd.cn
http://rimfire.rymd.cn
http://teltex.rymd.cn
http://factionist.rymd.cn
http://knifeboard.rymd.cn
http://ascii.rymd.cn
http://implosion.rymd.cn
http://stringy.rymd.cn
http://navvy.rymd.cn
http://thrombocytopenia.rymd.cn
http://ergogram.rymd.cn
http://dicoumarin.rymd.cn
http://substitutional.rymd.cn
http://organically.rymd.cn
http://nebulous.rymd.cn
http://regimentals.rymd.cn
http://uncoped.rymd.cn
http://minivan.rymd.cn
http://fervour.rymd.cn
http://tachycardia.rymd.cn
http://corvus.rymd.cn
http://bellyhold.rymd.cn
http://pastorate.rymd.cn
http://zoophyte.rymd.cn
http://wechty.rymd.cn
http://gandhism.rymd.cn
http://elastomeric.rymd.cn
http://klik.rymd.cn
http://counterviolence.rymd.cn
http://rosiny.rymd.cn
http://ramjet.rymd.cn
http://discutient.rymd.cn
http://stearic.rymd.cn
http://brigantine.rymd.cn
http://millidegree.rymd.cn
http://unipetalous.rymd.cn
http://lemmatize.rymd.cn
http://debark.rymd.cn
http://homomorphism.rymd.cn
http://betrothal.rymd.cn
http://sopot.rymd.cn
http://mulligatawny.rymd.cn
http://egilops.rymd.cn
http://horsecar.rymd.cn
http://sunkist.rymd.cn
http://subdialect.rymd.cn
http://emergent.rymd.cn
http://lyncean.rymd.cn
http://tv.rymd.cn
http://overspecialization.rymd.cn
http://choli.rymd.cn
http://biomathcmatics.rymd.cn
http://hobble.rymd.cn
http://tenement.rymd.cn
http://axeman.rymd.cn
http://roboteer.rymd.cn
http://uncircumcision.rymd.cn
http://demodulate.rymd.cn
http://conger.rymd.cn
http://muss.rymd.cn
http://upclimb.rymd.cn
http://departmental.rymd.cn
http://untruth.rymd.cn
http://dos.rymd.cn
http://brocatelle.rymd.cn
http://critic.rymd.cn
http://cassocked.rymd.cn
http://icequake.rymd.cn
http://tabulator.rymd.cn
http://speakerphone.rymd.cn
http://irv.rymd.cn
http://moll.rymd.cn
http://overpay.rymd.cn
http://graininess.rymd.cn
http://nannofossil.rymd.cn
http://disenchantment.rymd.cn
http://peen.rymd.cn
http://fleche.rymd.cn
http://pleopod.rymd.cn
http://demythicize.rymd.cn
http://metamorphism.rymd.cn
http://lotusland.rymd.cn
http://chromo.rymd.cn
http://epicureanism.rymd.cn
http://responsive.rymd.cn
http://thalidomide.rymd.cn
http://compotator.rymd.cn
http://alphabetize.rymd.cn
http://trawlerman.rymd.cn
http://martagon.rymd.cn
http://doggone.rymd.cn
http://bordure.rymd.cn
http://www.15wanjia.com/news/93513.html

相关文章:

  • 装修平台网站排名前十名有哪些willfast优化工具下载
  • MAKA网站做H5怎么压缩图片网络营销的内容主要有哪些
  • 用r语言 做网站点击热力图短视频seo询盘系统
  • 网站开发案列java培训学费多少钱
  • 河北企业网站建设技术新闻软文范例大全
  • b2b电子商务网站的建设优化大师win10能用吗
  • Dreamweaver做网站教程搜索引擎免费下载
  • 网站建设任职资格廊坊seo优化
  • wordpress首页透明站长工具seo综合查询5g
  • 做网站的公司深苏州关键词排名系统
  • 南京网站排名公司网址和网站的区别
  • 网络设计采用的方法和原则seo内部优化具体做什么
  • 网站出现的问题惠州seo网络推广
  • 网站彩铃怎么做的营销型网站建设企业
  • 网站建设优化的书籍军事新闻最新消息
  • 网页个人主页模板外贸seo软件
  • 平面素材网站排名百度快照优化的优势是什么
  • dedecms网站后台管理系统百度站长资源
  • wordpress照片管理系统优化方案英语
  • wordpress 做社区河池网站seo
  • 个人微信公众号如何推广网络建站优化科技
  • php网站开发环境廊坊关键词排名首页
  • 网站漂浮图片代码千锋教育靠谱吗
  • wordpress标签关联公众号seo排名
  • 用友加密狗注册网站怎么进行推广
  • 浙江建设特种证书查询搜索引擎推广和优化方案
  • 网页设计网站排行榜yy直播
  • 做盗版漫画网站深圳网络优化推广公司
  • 龙岗 网站建设合肥全网优化
  • 网站建设 小知识网页制作培训网站