Browse Source

tmp 在程序目录

liuyuqi-dellpc 5 years ago
parent
commit
0435e1a171
1 changed files with 11 additions and 4 deletions
  1. 11 4
      qr/qr.go

+ 11 - 4
qr/qr.go

@@ -1,17 +1,24 @@
 package qr
 
 import (
+	"log"
+	"os"
 	"os/exec"
+	"path/filepath"
 
 	"github.com/skip2/go-qrcode"
 )
 
 // RenderString as a QR code
 func RenderString(s string) {
-	err := qrcode.WriteFile(s, qrcode.Medium, 200, "tmp.png")
-	if err != nil {
-		panic(err)
+	dir, err1 := filepath.Abs(filepath.Dir(os.Args[0]))
+	if err1 != nil {
+		log.Fatal(err1)
 	}
-	cmd:=exec.Command("rundll32.exe", "url.dll,FileProtocolHandler", "tmp.png")
+	err2 := qrcode.WriteFile(s, qrcode.Medium, 200, dir+"/tmp.png")
+	if err2 != nil {
+		panic(err2)
+	}
+	cmd := exec.Command("rundll32.exe", "url.dll,FileProtocolHandler", dir+"/tmp.png")
 	cmd.Start()
 }