diff --git a/pkg/ctl/exportcredentials/cmd.go b/pkg/ctl/exportcredentials/cmd.go index 28110f39..1a531958 100644 --- a/pkg/ctl/exportcredentials/cmd.go +++ b/pkg/ctl/exportcredentials/cmd.go @@ -46,7 +46,7 @@ var cmd = &cobra.Command{ ctlcommon.ExitIfError(err) if opt.format == formatEnvironmentVariables && len(args) > 0 { - err = runUserCommands(context.Background(), *cred, args, nil, nil) + err = runUserCommands(context.Background(), *cred, args, nil, nil, nil) ctlcommon.ExitIfError(err) return } diff --git a/pkg/ctl/exportcredentials/exec.go b/pkg/ctl/exportcredentials/exec.go index 22694505..83e9c9f0 100644 --- a/pkg/ctl/exportcredentials/exec.go +++ b/pkg/ctl/exportcredentials/exec.go @@ -31,8 +31,12 @@ var ( } ) -func runUserCommands(ctx context.Context, cred Credentials, args []string, stdout io.Writer, stderr io.Writer) error { +func runUserCommands(ctx context.Context, cred Credentials, args []string, + stdin io.Reader, stdout io.Writer, stderr io.Writer) error { cmd := exec.CommandContext(ctx, args[0], args[1:]...) // #nosec G204 + if stdin == nil { + stdin = os.Stdin + } if stdout == nil { stdout = os.Stdout } @@ -42,6 +46,7 @@ func runUserCommands(ctx context.Context, cred Credentials, args []string, stdou envs := getCredentialsEnvsWithCurrentEnvs(cred) envs = append(envs, "ALIBABACLOUD_IGNORE_PROFILE=TRUE") cmd.Env = envs + cmd.Stdin = stdin cmd.Stdout = stdout cmd.Stderr = stderr