草庐IT

Shell-Command-Heavy

全部标签

go - 有什么办法可以在 exec.Command 中执行多个命令?

我正在尝试使用exec.Command()在Go中执行一组命令。我正在尝试使用DockerExec分离Gluster对等体。fmt.Println("Abouttoexecuteglusterpeerdetach")SystemdockerCommand:=exec.Command("sh","-c","dockerexec","9aa1124","glusterpeerdetach","192.168.1.1","force")varoutbytes.Buffervarstderrbytes.BufferSystemdockerCommand.Stdout=&outSystemdoc

戈朗 : go command inside script?

我有一个用Golang编写的脚本,我不太明白。我想知道他为什么要在脚本里面写goserver.Start()?为什么不简单地编写server.Start?packagemainimport("github.com/miekg/dns""testing""time")constTEST_ADDR="127.0.0.1:9953"funcTestDNSResponse(t*testing.T){server:=NewDNSServer(&Config{dnsAddr:TEST_ADDR,})goserver.Start()//Allowsometimeforservertostarttim

go - 如何在交互式 shell 中执行多个命令

我的应用程序使用控制台提供的所有类型的shell命令(curl、date、ping等等)。现在,我想使用os/exec来介绍交互式shell命令(如mongoshell)的案例。例如第一步,连接到mongodb:mongo--quiet--host=localhost博客然后执行任意数量的命令,获取每一步的结果db.getCollection('posts').find({status:'INACTIVE'})然后退出我尝试了以下方法,但它只允许我为每个mongo连接执行一个命令:funcmain(){cmd:=exec.Command("sh","-c","mongo--quiet-

go - shell提示时自动输入定义的密码?

我正在编写一个将运行一些bash脚本的Golang应用程序。在其中一个命令中,脚本将作为sudo运行,并且需要我手动输入密码。请问如何实现自动发送密码?cmd:=exec.Command("/bin/sh","-c","knifebootstrapxxx.xxx.xxx.xxx-xuser_name--sudo-i~/.ssh/id_rsa.pub--node-namenode_name-Ppassword-c~/chef-repo/.chef/config.rb")stdin,err:=cmd.StdinPipe()iferr!=nil{log.Panic(err)}gofunc()

shell - GO 支持使用 native 系统 shell 构建 CLI 工具

关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭7年前。Improvethisquestion我打算使用GO构建一个在native系统shell而不是单独的shell中执行的CLI工具。除了codegangsta/cli之外,GO的哪些包可以用于此目的?此外,有没有什么包可以获取RESTAPI调用支持(比如curl)在去?

Golang、exec 和 back ticks shell 命令

我正在尝试将os.exec(https://nathanleclaire.com/blog/2014/12/29/shelled-out-commands-in-golang/)与如下命令一起使用:value=`something`;echo$value但似乎后面的刻度线在扰乱字符串的命令。Split我是这样做的。如果我使用something它有效如何使用反引号?我必须找到另一种方式来编写我的命令吗?谢谢 最佳答案 Go以一种你不能使用shell的方式执行这些命令,因为它创建了一个新进程。所以你应该创建一个新的shell进程,例如:

windows - 在 go lang 中使用 exec.command 进行网络使用

我需要使用go映射Windows中的驱动器,发现此链接很有用Whatisthebestwaytomapwindowsdrivesusinggolang?当我尝试使用这里给出的代码时,我遇到了这个错误exec:"netuse":executablefilenotfoundin%PATH%我验证了go的bin文件夹在PATH变量中。我也试过像cmd,err:=exec.Command("cmd","/c","NETUSE","T:",\\SERVERNAME\C$,"/PERSISTENT").CombinedOutput()但是我得到这个错误:exitstatus1Youusedanop

go - 安装一个 go 脚本以从 shell 运行

我有一个名为SSL_CHECK.go的go脚本.现在要运行它,我需要以gorunSSL_CHECK.go>运行它我想编译这个脚本,以便我可以将它作为shell命令来执行。例如./ssl_check>来自外壳。我可以在Go中实现吗? 最佳答案 如果您的SSL_CHECK.go在包main中,您需要做的就是goinstall(如“Compileandinstallpackagesanddependencies”)。这将生成一个SSH_CHECK可执行文件并将其放入您的$GOPATH/bin文件夹中,该文件夹应该在您的$PATH中引用。

go - k8s oidc 问题与帮助程序包 (k8s-oidc-helper : command not found)

我在安装go时遇到了k8s-oidc-helper包的问题。但是,当我用它运行任何命令时,它会给出命令未找到错误。我在ubuntu16.04VM上运行它。我该如何解决这个问题? 最佳答案 我已经解决了这个问题。`go'的路径集不正确我检查了go的环境并相应地设置了路径。exportGOPATH=/usr/lib/goexportPATH=$PATH:$GOPATH/binsudogoget-ugithub.com/micahhausler/k8s-oidc-helper现在帮助程序包可以工作了

go - 传递变量作为 exec.Command() 的参数

我想读取用户输入并将其用作命令的参数。我得到了这段代码:packagemainimport("bufio""fmt""log""os""os/exec")funcmain(){reader:=bufio.NewReader(os.Stdin)fmt.Print("Enterimgpath:")imgPath,_:=reader.ReadString('\n')args:=[]string{imgPath,"stdout","-lspa+eng"}out,err:=exec.Command("tesseract",args...).Output()iferr!=nil{log.Fatal