草庐IT

shell-execute

全部标签

go - 将 `go` 与 fish shell 一起使用

我正在努力在fishshell中运行go。A)我遵循了安装过程并按照documentation中的说明安装了go但是,当我运行goversion时,出现fatalerror:fatal:notagitrepository(oranyparentuptomountpoint/)Stoppingatfilesystemboundary(GIT_DISCOVERY_ACROSS_FILESYSTEMnotset).当我通过gitinit初始化git时,我收到另一个错误:error:pathspec'version'didnotmatchanyfile(s)knowntogit我在我的fish

shell - 如何使用 Go 程序中的点脚本运行 graphviz 进程?

我想运行一个输出到图像的点脚本。我如何从Golang调用它?packagemainimport("fmt""os/exec")funcmain(){path,err:=exec.LookPath("dot")cmd:=exec.Command(path,"-Tpng","/Users/arafat/Desktop/dev/go/src/github.com/Arafatk/dataviz/DotExamples/arraylist.dot",">","/Users/arafat/Desktop/dev/go/src/github.com/Arafatk/dataviz/hello.pn

shell - Golang exec.Command 在退出代码不为零时返回 nil 错误

我正在尝试在Golang中运行一个命令,但看起来它丢失了退出代码,因为错误为nil:funcrunCommand()[]byte,error{cmd:=exec.Command("/bin/bash","-c","KUBECONFIG=/tmp/.kube/confighelmversion")cmd.Stdin=os.Stdincmd.Stderr=os.StderrstdOut,err:=cmd.StdoutPipe()iferr!=nil{returnnil,err}iferr:=cmd.Start();err!=nil{returnnil,err}bytes,err:=iout

go - 通过 Golang 执行 shell 脚本后返回错误

我有一个简单的shell脚本(名为copy.sh),如下所示:-#!/bin/shcp$1$2我执行了chmod777copy.sh。我有一个执行上述shell代码的golang代码:-packagemainimport("fmt""os/exec")funcmain(){_,err:=exec.Command("/Users/debraj/copy.sh","/Users/debraj/temp.txt","/Users/debraj/gotest/").Output()iferr!=nil{fmt.Println("Failedtoexecutecommand"+err.Error

templates - Golang setCookie() 在模板 Execute() 之后失败

作为GO的初学者,我遇到了如下情况:t,err:=template.ParseFiles("/template/login.tpl")err=t.Execute(w,nil)//ifexecutedbeforeSetCookiehttp.SetCookie(...)//failed,browserreceivednothing如果顺序改变,先到SetCookie,就可以了。我的计划是在login.tpl中ParseForm()用户名和密码,如果成功,sessionID将由发送>设置Cookie。但是现在SetCookie()必须放在login.tpl被Executed之前,这也使得Pa

bash - 在程序化 shell 命令执行中嵌入环境变量

我正处于尝试执行shell命令的情况,但它的参数被正确解释为环境变量。例如,当我在终端中输入以下内容时ls$GOPATHBash解释并扩展变量$GOPATH,并列出$GOPATH目录的内容。我正在尝试对Golang的程序化shell执行做类似的事情。我有以下代码。packagemainimport("bytes""fmt""log""os""os/exec")funcmain(){cmd:=exec.Command("echo","$TESTVAR")cmd.Env=append(os.Environ(),"TESTVAR=this_is_a_test",)varoutBuffbyte

shell - 如何为 go bin 提供命令

我使用以下代码创建命令,该命令应根据一些标志运行从cli传递。我使用cobra存储库https://github.com/spf13/cobra当我用gorunmain.goechotest运行它时我明白了打印:测试有效。现在我运行goinstall打开bin目录并单击文件newApp(这是我的应用程序名称)然后打印Usage:MZR[command]AvailableCommands:echoEchoanythingtothescreenhelpHelpaboutanycommandprintPrintanythingtothescreenFlags:-h,--helphelpfor

templates - tmpl.Execute 和子文件 golang

我需要帮助。我需要在子文件("article.html",我的文本中的示例)://...typePagestruct{Teststring}typeNewsstruct{PageTitlestring}funcmain(){t,_:=template.ParseFiles(filepath+"core.tmpl",filepath+"article.tmpl")p:=&News{Title:"TITLE",Page:Page{Test:"TITLE",},}t.Execute(wr,p)}core.tmpl中的代码:{{template"article"}}article.tmpl中的

bash - 停止 shell 通配符扩展?

编译后的命令行程序是否有任何方法可以告诉bash或csh它不希望扩展其参数中的任何通配符?例如,一个人可能想要这样的shell命令:foo*简单地返回该字符的数字ASCII值。 最佳答案 没有。扩展发生在命令实际运行之前。您只能在运行命令之前或通过引用星号来禁用glob。$#quoteit$foo'*'$#orescapeit$foo\*$#ordisabletheglob(noglob)$set-f$foo*$#alternativetoset-f$set-onoglob$#undoitby$set+onoglob

macos - 更新到 macOS beta 4 后,go test -cover 抛出 "fatal error: unexpected signal during runtime execution"

Gobuild和gotest仍然有效。在更新到macOSbeta之前,我使用测试覆盖工具没有遇到任何问题。“去测试”工作正常;但是,所有覆盖率测试命令都抛出此错误(gotest-coverprofile=coverage.out抛出相同的问题)。如果有人知道如何解决这个问题,我将不胜感激!$gotest-covergobuildgithub.com/hunteramericano/ErrorQuiver:/usr/local/Cellar/go/1.6.3/libexec/pkg/tool/darwin_amd64/cover:signal:fatalerror:unexpecteds