Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run WSL command without opening CMD Window #123

Open
pclass-isolated opened this issue Oct 3, 2024 · 0 comments
Open

How to run WSL command without opening CMD Window #123

pclass-isolated opened this issue Oct 3, 2024 · 0 comments

Comments

@pclass-isolated
Copy link

How can I hide the CMD windows that opens when I run a WSL command? I tried the following, but the command object is missing the attribute for hidden window flag. My goal is to run a WSL command without opening a CMD window on Windows 11. Thanks.

// Get the command
cmd := distro.Command(context.Background(), command)

// Ensure to hide the window
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} // This fails to compile

// Run wsl command and get output
out, err := cmd.CombinedOutput()
if err != nil {
    fmt.Fprintf(os.Stderr, "Unexpected error: %v\nError message: %s", err, out)
    return errors.New("Error: Failed to run command: " + fmt.Sprintf("Unexpected error: %v\nError message: %s", err, out))
} else {
    pp.Println("WSL: " + string(out))
    return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant