I have a go program that should invoke a ruby script.
I have a runCommand function:
func runCommand(cmdName string, arg ...string) {
cmd := exec.Command(cmdName, arg...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
err = cmd.Run()
if err != nil {
fmt.Printf("Failed to start Ruby. %s\n", err.Error())
os.Exit(1)
}
}
I invoke it like this:
runCommand("ruby", "-e", "require 'foo'")
It works for most cases, except if there is a gets or any similar operation in the child process that needs to pause for an input.
I have tried setting cmd.Stdin = os.Stdin, but it does not wait for input.
What am I doing wrong?
getsin Ruby, can you enter input from your console? Does Ruby wait for that? Do you hit Enter after entering your input?getsis in middle of a flow, and if I run the ruby script it waits for an input. Yes, I hit enter after the input. My real usecase is to invokepryon the ruby side, and my expectation iscmd.Run()would wait for thepryREPL to complete.Errormethod. And if you're going to exit, you can send output to stderr and exit via thelogpackge. I.e. justlog.Fatal("Failed to start Ruby:", err)will do.Stdinat the first level.