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

Ignore interrupts and wait for child process to exit #119

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions cmd/godotenv/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"flag"
"fmt"
"log"
"os"
"os/exec"
"os/signal"

"strings"

Expand Down Expand Up @@ -43,12 +46,24 @@ example
envFilenames = strings.Split(rawEnvFilenames, ",")
}

if err := godotenv.Load(envFilenames...); err != nil {
log.Fatal(err)
}

// take rest of args and "exec" them
cmd := args[0]
cmdArgs := args[1:]

err := godotenv.Exec(envFilenames, cmd, cmdArgs)
if err != nil {
command := exec.Command(cmd, cmdArgs...)
command.Stdin = os.Stdin
command.Stdout = os.Stdout
command.Stderr = os.Stderr

// Ignore interrupts so we don't exit before the sub-process does.
// This signal will still get passed to the sub-process.
signal.Ignore(os.Interrupt)

if err := command.Run(); err != nil {
log.Fatal(err)
}
}