如何在Golang中运行exec.Command时调试“exit status 1”错误
来源:互联网 发布:js 随机数 生成原理 编辑:程序博客网 时间:2024/06/17 03:20
当我运行下面的代码:
cmd := exec.Command("find", "/", "-maxdepth", "1", "-exec", "wc", "-c", "{}", "\\")var out bytes.Buffercmd.Stdout = &outerr := cmd.Run()if err != nil { fmt.Println(err) return}fmt.Println("Result: " + out.String())
我收到这个错误:
exit status 1
但是,这对调试错误的确切原因没有帮助。
如何获取更详细的信息?
最多投票
向下投票
向下投票
解决方案是使用Stderr
Command对象的属性。这可以这样做:
cmd := exec.Command("find", "/", "-maxdepth", "1", "-exec", "wc", "-c", "{}", "\\")var out bytes.Buffervar stderr bytes.Buffercmd.Stdout = &outcmd.Stderr = &stderrerr := cmd.Run()if err != nil { fmt.Println(fmt.Sprint(err) + ": " + stderr.String()) return}fmt.Println("Result: " + out.String())
运行上面的代码,会明确问题是什么:
退出状态1:查找:-exec:无终止“;” 或“+”
阅读全文
0 0
- 如何在Golang中运行exec.Command时调试“exit status 1”错误
- [Python]安装PIL出现command 'gcc' failed with exit status 1错误
- 安装MySQL-python时发生错误:error: command 'gcc' failed with exit status 1
- Scrapy安装步骤及错误汇总:scrapy OpenSSL error: command ‘gcc’ failed with exit status 1
- Scrapy安装步骤及错误汇总:scrapy OpenSSL error: command ‘gcc’ failed with exit status 1
- MySQL-python “error: command 'gcc' failed with exit status 1”错误
- 安装MySQL-python时发生错误:error: command 'gcc' failed with exit status 1
- 关于error: command 'gcc' failed with exit status 1错误的解决方法的一些总结
- 关于Python安装模块出现error: command 'gcc' failed with exit status 1错误的解决方法
- golang执行命令 exec.Command
- collect2: ld returned 1 exit status错误.
- collect2: ld returned 1 exit status错误.
- 错误[Error] ld returned 1 exit status
- hadoop运行时错误:Task process exit with nonzero status of 1
- K8S中pod在挂载volume时出现FailedMount错误(exit status 32)
- error: command 'gcc' failed with exit status 1
- error: command 'gcc' failed with exit status 1
- error: command 'gcc' failed with exit status 1
- android js 交互
- 使用dom4j解析xml与增删改查
- 归一化
- c++11实现的一个消息总线框架
- Android StackView用法
- 如何在Golang中运行exec.Command时调试“exit status 1”错误
- Python开发爬虫,爬取网站
- 分布式集群系统下的高可用session解决方案
- 虚函数和虚析构函数的实现原理--虚函数表
- Hadoop学习计划
- 使用Oracle SQL Developer迁移MySQL至Oracle数据库
- kaldi的语音识别数据timit例子详解
- k-means和EM算法的Matlab实现
- 一个项如何能不放在webApps文件夹中也能进行访问