草庐IT

Command_Line_Tools_OS_X

全部标签

go - 以编程方式为 os.Process 编写标准输入

更新:要以编程方式“驱动”bash,您需要一个伪终端(PTY)。这就是我要找的:https://github.com/kr/ptypackagemainimport("github.com/kr/pty""io""os""os/exec")funcmain(){c:=exec.Command("grep","--color=auto","bar")f,err:=pty.Start(c)iferr!=nil{panic(err)}gofunc(){f.Write([]byte("foo\n"))f.Write([]byte("bar\n"))f.Write([]byte("baz\n")

go - 你如何将 syscall.Errno 传递给 os.Exit?

假设我尝试获取锁,但失败了,然后想退出程序。err=syscall.Flock(lockfd,syscall.LOCK_EX|syscall.LOCK_NB)iferr==syscall.EAGAIN{os.Exit(err)}问题是您需要将一个整数传递给os.Exit。我试过:os.Exit(int(err))os.Exit(syscall.EAGAIN)//Compilesfine,butthecastfails..noideawhyeerr,_:=err.(*syscall.Errno);os.Exit(int(*eerr))//panicsreflect.ValueOf(err

go - 如何在 go 中使用 os.Name()?

我正在尝试使用:https://golang.org/src/os/file.go?s=1472:1577#L35通过导入“os”包然后运行f,err:=os.Open("/tmp/dat3")check(err)name:=os.Name(f)我得到./main.go:29:undefined:os.Name为什么?我究竟做错了什么。(我当然知道我有打开文件的名称-但我很好奇为什么,我无法调用该函数) 最佳答案 因为Name是定义在File结构上的特殊函数(method)。意味着它采用File类型作为接收器,并且可以使用接收器实例

go - 是什么导致了这种 go​​lang os.Exec 行为(转义双引号)?

我有以下代码:fori:=0;i如果我改变有效负载行payload:="--post-data=id=fi.danskebank.mobilepay&reviewSortOrder=2&xhr=1&reviewType=0&pageNum="+strconv.Itoa(i)到payload:="--post-data=\"id=fi.danskebank.mobilepay&reviewSortOrder=2&xhr=1&reviewType=0&pageNum="+strconv.Itoa(i)+"\""它将返回服务器错误500,即使在运行相应的wget时也是如此:wget--use

macos - 无法在 mac os 上使用 Go 命令行

我想使用命令goget,但它抛出异常但我已经安装了命令行工具。系统:macOssierra10.12.6Go:1.9.2编辑:错误信息:gogetgithub.com/hashicorp/go-plugin#cd.;gitclonehttps://github.com/hashicorp/go-plugin/Users/famoss/files/goworkspace/src/github.com/hashicorp/go-pluginxcrun:error:activedeveloperpath("/Applications/Xcode.app/Contents/Developer"

bash - 使用 os.exec 执行 'su' 返回错误

据我了解,Go的exec函数直接使用内核执行命令,而不是创建本地终端session或类似的东西。不幸的是,我需要使用su命令来运行脚本,这涉及运行su然后通过标准输入管道输入root密码。是的,我必须使用su(禁用sudo的设备上的业务用例),而且我还需要能够通过管道输入密码。目前我的代码如下rootRun:=exec.Command("su","-c","whoami")rootRun.Stderr=os.StdoutrootRun.Stdout=os.Stdouterr=rootRun.Run()check(err)错误是su:mustberunfromaterminalpanic

go - exec.Command 调用 java cli

如何让exec.Command命令从另一个文件调用命令?funcmain(){fmt.Println("Iniciando...")command:=exec.Command("java-version")command.Dir="."output,err:=command.Output()iferr!=nil{fmt.Println("Erro:",err)}fmt.Printf("%s",output)}错误:exec:“java-version”:在$PATH中找不到可执行文件 最佳答案 每个参数都需要在自己单独的字符串中。试

go - bufio.NewReader(os.Stdin) 和 fmt.Scanln() 有什么区别

关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭3年前。Improvethisquestionpackagemainimport("bufio""fmt""os")funcmain(){in:=bufio.NewReader(os.Stdin)fmt.Println("PleaseinputS:")S,_:=in.ReadString('\n')fmt.Println("PleaseinputJ:")J,_:=in.ReadString('\n')sum:=numJewelsInStone

file - Golang 添加自定义 os.File 到 os.Stdout

每当我向控制台打印内容时,我都试图将输出写入文件。似乎没有任何使用连续流的好例子,而是读取单个值,所以我想出了以下代码:packagemainimport("fmt""io""os")typeahhhstruct{*os.File__writerio.Writer}func(me*ahhh)Write(b[]byte)(nint,errerror){returnme.__writer.Write(b)}funcwrite_print_to_file(file_namestring){file,_:=os.OpenFile(file_name,os.O_RDWR|os.O_CREATE|

go - exec.Command 错误,没有输出到 stdout 或 stderr

我正在尝试使用ffprobe和exec.Command获取视频的持续时间,但我一直收到错误消息。但是,stdout和stderr都是空的,所以我不知道问题出在哪里。funcgetVideoLength(filenamestring)float64{cmd:=exec.Command("ffprobe","-i",filename,"-show_entries","format=duration","-v","quiet","-of","csv=\"p=0\"")fmt.Println("ffprobe","-i",filename,"-show_entries","format=dur