英文:
How can I transfer from a console app written in "go" to another console app?
问题
我想用"go"编写一个控制台应用程序,它将控制权转移到另一个控制台应用程序。
以下是步骤:
- 运行二进制应用程序,如果需要,验证并安装一些内容
- 二进制应用程序构建一个带有选项的命令字符串
- 二进制应用程序启动进程B并退出(在我的情况下是一个Node.js应用程序)
- 进程B运行完成并将输出发送到同一个控制台。
我唯一需要的步骤是启动一个新进程并退出,这就是这里的问题。
英文:
I want to write a console application using "go" that will transfer control to another console application.
Here are the steps:
- run binary app which validates and installs a few things if necessary
- binary app constructs a command string with options
- binary app starts process B and exits (a node.js app in my case)
- Process B runs to completion and sends output to the same console.
The ONLY step I need is the ability to start a new process and exit, so that is the question here.
答案1
得分: 1
os包看起来具有你可能需要的功能。函数StartProcess用于启动一个进程,函数(*Process) Kill用于退出进程。
英文:
The os package looks like it has the functionality you might need.
The function StartProcess for starting a process and the function (*Process) Kill to exit it.
答案2
得分: 1
os/exec
可能会有帮助:
> 包exec用于运行外部命令。它包装了os.StartProcess,使得重新映射标准输入和标准输出、连接I/O管道和进行其他调整更加容易。
请查看Cmd.Start
示例。
英文:
os/exec
might be helpful:
> Package exec runs external commands. It wraps os.StartProcess to make it easier to remap stdin and stdout, connect I/O with pipes, and do other adjustments.
Check out the Cmd.Start
example.
答案3
得分: 1
请参考 https://stackoverflow.com/questions/10027477/golang-fork-process。简而言之,直接这样做存在问题。您应该使用非Go程序来启动您的node.js应用程序。
英文:
See https://stackoverflow.com/questions/10027477/golang-fork-process. In short, there are issues with doing this directly. You should instead use a non-Go program to start your node.js app.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论