douhan4812 2014-12-10 08:25
浏览 158

golang exec.Command无法运行C二进制文件

I executing a C executable using exec.Command and exec.Start(). My C executable is in the current directory and this is my code

cmd := exec.Command("./a.out")
// stdout,err := cmd.StderrPipe()
stderr,_ := cmd.StderrPipe()

err := cmd.Start()
if err != nil {
    log.Fatal(err)
}

log.Printf("Waiting for command to finish...")
s,err := ioutil.ReadAll(stderr)
log.Printf(string(s))
err = cmd.Wait()
log.Printf("Command finished with error: %v", err)

When i run this code, this is the output i get

2014/12/10 07:49:39 Waiting for command to finish...
2014/12/10 07:49:39 Command finished with error: exit status 11

My C hello world program is

#include <stdio.h>
int main(){
printf("hello world");
}

The C code is compiled with gcc version 4.8.2 and executable is a.out.

The C executable a.out is a simple hello world program, i am getting the correct output, but i can't understand why exec.Wait() is exiting with status code 11 and not with 0.

The executable('a.out') is running normally when i run on a linux terminal without any faults or errors

  • 写回答

1条回答 默认 最新

  • dongqiangteng7319 2014-12-10 15:25
    关注

    I got the answer from github here

    It is returning 11 because the output length is 11 and there is no return statement in my hello world program. So main returns from AX register when it ended.

    评论

报告相同问题?

悬赏问题

  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题