MCPcopy Index your code
hub / github.com/gopherdata/gophernotes / evalShellCommand

Function evalShellCommand

kernel.go:773–815  ·  view source on GitHub ↗

execute shell command. line must start with '$'

(ir *interp.Interp, outerr OutErr, line string)

Source from the content-addressed store, hash-verified

771
772// execute shell command. line must start with '$'
773func evalShellCommand(ir *interp.Interp, outerr OutErr, line string) {
774 args := strings.Fields(line[1:])
775 if len(args) <= 0 {
776 return
777 }
778
779 var writersWG sync.WaitGroup
780 writersWG.Add(2)
781
782 cmd := exec.Command(args[0], args[1:]...)
783
784 stdout, err := cmd.StdoutPipe()
785 if err != nil {
786 panic(fmt.Errorf("Command.StdoutPipe() failed: %v", err))
787 }
788
789 stderr, err := cmd.StderrPipe()
790 if err != nil {
791 panic(fmt.Errorf("Command.StderrPipe() failed: %v", err))
792 }
793
794 go func() {
795 defer writersWG.Done()
796 io.Copy(outerr.out, stdout)
797 }()
798
799 go func() {
800 defer writersWG.Done()
801 io.Copy(outerr.err, stderr)
802 }()
803
804 err = cmd.Start()
805 if err != nil {
806 panic(fmt.Errorf("error starting command '%s': %v", line[1:], err))
807 }
808
809 err = cmd.Wait()
810 if err != nil {
811 panic(fmt.Errorf("error waiting for command '%s': %v", line[1:], err))
812 }
813
814 writersWG.Wait()
815}

Callers 1

evalSpecialCommandsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected