1. 首页
  2. 主题
  3. Go问与答

如何用Go启动一个外部程序(linux平台)

lihainiao · · 3332 次点击
如何在Linux平台上用go拉起一个三方程序。 exec.command os.StartProcess syscal.Exec 以上浅试,都不行。哪位大神有办法
可行归可行,里面各种参数和分支处理起来很累人。用`os/exec`好了。 还有就是`>`、`>>`等只是shell自己的语法,脱离了shell环境就不能再用了。
#4
更多评论
调用python脚本start.py ```python #!/usr/bin/python import os os.system("nohup /home/fpz/git/ywpt/go-client/ywpt_client_upgrade/ZhengheMonitorClient-linux-0.1.0 >/dev/null &") ``` ```go startfile := "start.py" err5 := syscall.Exec(startfile, []string{">/dev/null"}, os.Environ()) ``` 这种方式会有输出直接导致go主进程结束 ![image.png](https://static.golangjob.cn/230519/f19e0dedcb2fc5eb1bb80659106ce988.png)
#1
syscall.Exec会直接在当前进程执行, 改用os.StartProcess(startfile, []string{""}, &os.ProcAttr{})可行
#2

用户登录

没有账号?注册

今日阅读排行

    加载中

一周阅读排行

    加载中