Starting a program in screen (linux) using golang

huangapple go评论79阅读模式
英文:

Starting a program in screen (linux) using golang

问题

我想在一个使用os/exec库的golang项目中,在Linux上启动一个.exe文件。
我通常使用"mono"来启动.exe文件,所以我做了以下操作:

command := make([]string, 7)
command = []string{"screen", "-S", screenName, "-d", "-m", "mono", exeFile}
cmd := exec.Command(command[0], command[1:]...)
cmd.Dir = "ConsoleClient"
_, err := cmd.Output() //*

我无法运行这个命令,我也尝试过使用cmd.Run()cmd.Start()

*使用cmd.Start()(对我来说是最好的方法),我没有看到任何错误,但最终没有创建screen。

我还尝试在我的命令末尾添加^M,但仍然失败。

英文:

I want to start a .exe file in linux inside a golang project using os/exec library.
I usually use "mono" to start .exe file so i did:

command := make([]string, 7)
command = {"screen", "-S", screenName, "-d", "-m", "mono", exeFile}
cmd := exec.Command(command[0], command[1:]...)
cmd.Dir = "ConsoleClient"
_, err := cmd.Output() //*

I cant run this and i tried also with cmd.Run() or cmd.Start()

*With cmd.Start() (for me the best way) i don't see any error but at the end screen isn't created

It failed also adding ^M at the end of my command

答案1

得分: 0

尝试将第2行改为以下内容:

command = {"screen", "-dmS", screenName, "mono", exeFile}

参数应该在屏幕名称之前。

英文:

Try this at line 2:

command = {"screen", "-dmS", screenName, "mono", exeFile}

parameters should be before the screen name.

huangapple
  • 本文由 发表于 2021年11月28日 23:01:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/70144624.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定