mirror of
https://github.com/tjboldt/Apple2-IO-RPi.git
synced 2025-02-16 18:30:29 +00:00
Update exec command to stream text
This commit is contained in:
parent
64441085bf
commit
e492527399
@ -118,6 +118,7 @@ func ReadByte() (byte, error) {
|
|||||||
// wait for the Apple II to write
|
// wait for the Apple II to write
|
||||||
for in_write.Read() == gpio.High {
|
for in_write.Read() == gpio.High {
|
||||||
if !in_write.WaitForEdge(edgeTimeout) {
|
if !in_write.WaitForEdge(edgeTimeout) {
|
||||||
|
out_read.Out(gpio.High)
|
||||||
return 0, errors.New("Timed out reading byte -- write stuck high\n")
|
return 0, errors.New("Timed out reading byte -- write stuck high\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,6 +239,7 @@ func WriteByte(data byte) error {
|
|||||||
//fmt.Printf("wait for the Apple II to finsih reading\n")
|
//fmt.Printf("wait for the Apple II to finsih reading\n")
|
||||||
for in_read.Read() == gpio.Low {
|
for in_read.Read() == gpio.Low {
|
||||||
if !in_read.WaitForEdge(edgeTimeout) {
|
if !in_read.WaitForEdge(edgeTimeout) {
|
||||||
|
out_write.Out(gpio.High)
|
||||||
return errors.New("Timed out writing byte -- read stuck low")
|
return errors.New("Timed out writing byte -- read stuck low")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
"bufio"
|
||||||
|
|
||||||
"github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/a2io"
|
"github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/a2io"
|
||||||
)
|
)
|
||||||
@ -80,17 +81,40 @@ func ExecCommand() {
|
|||||||
}
|
}
|
||||||
cmd := exec.Command("bash", "-c", linuxCommand)
|
cmd := exec.Command("bash", "-c", linuxCommand)
|
||||||
cmd.Dir = workingDirectory
|
cmd.Dir = workingDirectory
|
||||||
cmdOut, err := cmd.Output()
|
stdout, err := cmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to execute command\n")
|
fmt.Printf("Failed to set stdout\n")
|
||||||
a2io.WriteString("Failed to execute command\r")
|
a2io.WriteString("Failed to set stdout\r")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Printf("Command output: %s\n", cmdOut)
|
fmt.Printf("Command output:\n")
|
||||||
apple2string := strings.Replace(string(cmdOut), "\n", "\r", -1)
|
err = cmd.Start()
|
||||||
err = a2io.WriteString(apple2string)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to send command output\n")
|
fmt.Printf("Failed to start command\n")
|
||||||
|
a2io.WriteString("Failed to start command\r")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reader := bufio.NewReader(stdout)
|
||||||
|
|
||||||
|
for err == nil {
|
||||||
|
var b byte
|
||||||
|
b, err = reader.ReadByte()
|
||||||
|
if err == nil {
|
||||||
|
fmt.Print(string(b))
|
||||||
|
if b == 10 { // convert LF to CR for Apple II compatiblity
|
||||||
|
b = 13
|
||||||
|
}
|
||||||
|
b |= 128
|
||||||
|
err = a2io.WriteByte(b)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("\nFailed to write byte\n")
|
||||||
|
cmd.Process.Kill()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Wait()
|
||||||
|
a2io.WriteByte(0)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user