Files
odo/pkg/podman/exec.go
Philippe Martin 6bc30110ba Display outputs when executing odo run (#6865)
* Change NewRunHandler params with Options

* Pass an options to RunHandler to show logs

* Hide spinner and std output since outputs are displayed

* Integration tests with failing command

* Fix outputs

* use raw terminal and local standard i/o streams

* Fix podman i/o

* Fix stdout/err

* Test if in/out are terminal

* command reference doc
2023-06-12 10:45:31 -04:00

32 lines
752 B
Go

package podman
import (
"context"
"fmt"
"io"
"os/exec"
"k8s.io/klog"
)
func (o *PodmanCli) ExecCMDInContainer(ctx context.Context, containerName, podName string, cmd []string, stdout, stderr io.Writer, stdin io.Reader, tty bool) error {
options := []string{}
if tty {
options = append(options, "--tty")
}
name := fmt.Sprintf("%s-%s", podName, containerName)
args := []string{"exec", "--interactive"}
args = append(args, options...)
args = append(args, name)
args = append(args, cmd...)
command := exec.CommandContext(ctx, o.podmanCmd, append(o.containerRunGlobalExtraArgs, args...)...)
command.Stdout = stdout
command.Stderr = stderr
command.Stdin = stdin
klog.V(3).Infof("executing %v", command.Args)
return command.Run()
}