From 9ef38ed4be732f4901ca10fec22a28281df13a70 Mon Sep 17 00:00:00 2001 From: galih rivanto Date: Mon, 15 Feb 2021 14:45:50 +0700 Subject: [PATCH] ignore error when querying version --- cmd/svg2pdf/main.go | 3 - cmd/svg2pdf/maincon.svg | 790 ++++++++++++++++++++++++++++++++++++++++ cmd/svg2pdf/xxx.svg | 1 + proxy.go | 19 +- 4 files changed, 804 insertions(+), 9 deletions(-) create mode 100644 cmd/svg2pdf/maincon.svg create mode 100644 cmd/svg2pdf/xxx.svg diff --git a/cmd/svg2pdf/main.go b/cmd/svg2pdf/main.go index 9eb5cb3..9210db0 100644 --- a/cmd/svg2pdf/main.go +++ b/cmd/svg2pdf/main.go @@ -3,7 +3,6 @@ package main import ( "flag" "fmt" - "log" "os" "github.com/galihrivanto/go-inkscape" @@ -35,8 +34,6 @@ func main() { proxy := inkscape.NewProxy(inkscape.Verbose(verbose)) - log.Println("run command") - err := proxy.Run() handleErr(err) defer proxy.Close() diff --git a/cmd/svg2pdf/maincon.svg b/cmd/svg2pdf/maincon.svg new file mode 100644 index 0000000..609057a --- /dev/null +++ b/cmd/svg2pdf/maincon.svg @@ -0,0 +1,790 @@ + + + + + + + image/svg+xml + + + + + + + + + + + CHANGI EAST + + Alan Xu Kefeng + SEMBCORP SPECIALISEDCONSTRUCTION + + + Serial No : + CON-0001 + + + diff --git a/cmd/svg2pdf/xxx.svg b/cmd/svg2pdf/xxx.svg new file mode 100644 index 0000000..0a35231 --- /dev/null +++ b/cmd/svg2pdf/xxx.svg @@ -0,0 +1 @@ +image/svg+xmlKAWI DEVLalalalaxcorpSerial No :SSC-9999 \ No newline at end of file diff --git a/proxy.go b/proxy.go index 9267cab..5c9a598 100644 --- a/proxy.go +++ b/proxy.go @@ -115,11 +115,15 @@ func (p *Proxy) runBackground(ctx context.Context, commandPath string, vars ...s // make first command available // after received prompt +wait: for { bytesOut := <-stdoutC bytesOut = bytes.TrimSpace(bytesOut) - if isPrompt(bytesOut[len(bytesOut)-1:]) { - break + parts := bytes.Split(bytesOut, []byte("\n")) + for _, part := range parts { + if isPrompt(part) { + break wait + } } } @@ -184,10 +188,10 @@ func (p *Proxy) Run(args ...string) error { }() // print inkscape version - res, err := p.RawCommands(Version()) + res, _ := p.RawCommands(Version()) fmt.Println(string(res)) - return err + return nil } // Close satisfy io.Closer interface @@ -251,8 +255,11 @@ waitLoop: break waitLoop case bytesOut := <-p.stdout: debug(string(bytesOut)) - if isPrompt(bytesOut) { - break waitLoop + parts := bytes.Split(bytesOut, []byte("\n")) + for _, part := range parts { + if isPrompt(part) { + break waitLoop + } } output = append(output, bytesOut...)