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