Open
Description
Here is my code, please check it out.
package main
import (
"bytes"
"fmt"
"log"
"os"
"os/exec"
"strconv"
kdb "github.com/sv/kdbgo"
)
var testPort = 0
func StartQ(ready chan struct{}) {
fmt.Println("Starting q process on random port")
_, err := exec.LookPath("q")
if err != nil {
log.Fatal("installing q is in your future")
}
cmd := exec.Co
54F3
mmand("q", "-p", "0W", "-q")
stdin, err := cmd.StdinPipe()
if err != nil {
log.Fatal("Failed to connect stdin", err)
}
stdin.Write([]byte(".z.pi:.z.pg:.z.ps:{value 0N!x};system\"p\"\n"))
stdout, err := cmd.StdoutPipe()
if err != nil {
log.Fatal("Failed to connect stdout", err)
}
stderr, err := cmd.StderrPipe()
if err != nil {
log.Fatal("Failed to connect stderr", err)
}
err = cmd.Start()
if err != nil {
log.Fatal("Failed to start q", err)
}
buf := make([]byte, 16)
n, err := stdout.Read(buf)
if err != nil {
log.Fatal("Failed to fill port number for child process: ", err)
}
testPort, err = strconv.Atoi(string(buf[:bytes.IndexByte(buf, 'i')]))
if err != nil {
fmt.Println("Failed to setup listening port", string(buf[:n]), err)
cmd.Process.Kill()
os.Exit(1)
}
fmt.Println("Listening port is ", testPort)
go func() {
for {
buf := make([]byte, 256)
n, err := stderr.Read(buf)
fmt.Println("Q stderr output:", string(buf[:n]))
if err != nil {
fmt.Println("Q stderr error:", err)
return
}
}
}()
go func() {
for {
buf := make([]byte, 256)
_, err := stdout.Read(buf)
//fmt.Println("Q stdout output:", string(buf[:n]))
if err != nil {
fmt.Println("Q stdout error:", err)
return
}
}
}()
ready <- struct{}{}
cmd.Wait()
//stdin.Write([]byte("show `exiting_process;\nexit 0\n"))
}
func main() {
ready := make(chan struct{})
go StartQ(ready)
<-ready
log.Println("Connect to kdb+ through unix socket.")
con, err := kdb.DialUnix("localhost", testPort, "")
if err != nil {
panic(err)
}
log.Println("Close the connection")
err = con.Close()
if err != nil {
panic(err)
}
}
Metadata
Metadata
Assignees
Labels
No labels