gproc_must.go 968 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package gproc
  7. import (
  8. "context"
  9. "io"
  10. )
  11. // MustShell performs as Shell, but it panics if any error occurs.
  12. func MustShell(ctx context.Context, cmd string, out io.Writer, in io.Reader) {
  13. if err := Shell(ctx, cmd, out, in); err != nil {
  14. panic(err)
  15. }
  16. }
  17. // MustShellRun performs as ShellRun, but it panics if any error occurs.
  18. func MustShellRun(ctx context.Context, cmd string) {
  19. if err := ShellRun(ctx, cmd); err != nil {
  20. panic(err)
  21. }
  22. }
  23. // MustShellExec performs as ShellExec, but it panics if any error occurs.
  24. func MustShellExec(ctx context.Context, cmd string, environment ...[]string) string {
  25. result, err := ShellExec(ctx, cmd, environment...)
  26. if err != nil {
  27. panic(err)
  28. }
  29. return result
  30. }