Something finally works.

This commit is contained in:
Andrey Parhomenko 2023-06-04 23:41:43 +03:00
parent ccc9c1a578
commit c52438956c
2 changed files with 21 additions and 11 deletions

View file

@ -21,9 +21,9 @@ import (
) )
type Cmd struct { type Cmd struct {
input io.Reader input io.ReadCloser
*exec.Cmd *exec.Cmd
output io.Writer output io.WriteCloser
} }
const version = "0.1.8" const version = "0.1.8"
@ -109,13 +109,15 @@ func setupEnv() {
panic(err) panic(err)
} }
ibuf := make([]byte, 512)
obuf := make([]byte, 512) obuf := make([]byte, 512)
go func() { go func() {
var (
err error
n int
)
for { for {
no, err := stdout.Read(obuf) n, err = stdout.Read(obuf)
output.Write(obuf[:no]) output.Write(obuf[:n])
if err == io.EOF { if err == io.EOF {
break break
} else if err != nil { } else if err != nil {
@ -125,10 +127,15 @@ func setupEnv() {
stdout.Close() stdout.Close()
}() }()
ibuf := make([]byte, 512)
go func() { go func() {
var (
err error
n int
)
for { for {
ni, err := input.Read(ibuf) n, err = input.Read(ibuf)
stdin.Write(ibuf[:ni]) stdin.Write(ibuf[:n])
if err == io.EOF { if err == io.EOF {
break break
} else if err != nil { } else if err != nil {
@ -140,10 +147,11 @@ func setupEnv() {
err = rcmd.Wait() err = rcmd.Wait()
if err != nil { if err != nil {
fmt.Println("shit", err) //fmt.Println(err)
return false
} }
return err == nil return true
}) })
core.Import(e) core.Import(e)
} }

View file

@ -1,3 +1,5 @@
rcmd("dir") if rcmd("ls") {
rcmd("goblin", "echo", "full shit")
}