Skip to content

Instantly share code, notes, and snippets.

@suzuki-shunsuke
Last active August 25, 2019 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suzuki-shunsuke/5553aaeb5a932e1bc0a74f3b485b0a9e to your computer and use it in GitHub Desktop.
Save suzuki-shunsuke/5553aaeb5a932e1bc0a74f3b485b0a9e to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
"os/exec"
)
func main() {
cmd := exec.Command("sh", "-c", "ls | fzf")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
// it works as expected.
if err := cmd.Run(); err != nil {
fmt.Println(err)
}
}
package main
import (
"context"
"fmt"
"os"
"os/exec"
"time"
"github.com/Songmu/timeout"
)
func main() {
cmd := exec.Command("sh", "-c", "ls | fzf")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
tio := &timeout.Timeout{
Cmd: cmd,
Duration: 10 * time.Second,
KillAfter: 5 * time.Second,
// Foreground: true,
}
// it doesn't work as expected.
exitStatus, err := tio.RunContext(context.Background())
fmt.Println(exitStatus, err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment