提交 39efe303 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

get interpreter info by lang

上级 e68a7e1d
......@@ -33,7 +33,7 @@ var (
"printGrammar": "console.log(\"#\")",
"interpreter": "C:\\Program Files\\nodejs\\node.exe",
"whereCmd": "where node",
"versionCmd": "%s -v",
"versionCmd": "-v",
},
"lua": {
"name": "Lua",
......@@ -42,7 +42,7 @@ var (
"printGrammar": "print('#')",
"interpreter": "C:\\Program Files (x86)\\Lua\\5.1\\lua.exe",
"whereCmd": "where lua",
"versionCmd": "%s -v",
"versionCmd": "-v",
},
"perl": {
"name": "Perl",
......@@ -51,7 +51,7 @@ var (
"printGrammar": "print \"#\\n\";",
"interpreter": "C:\\Perl64\\bin\\perl.exe",
"whereCmd": "where perl",
"versionCmd": "%s -v",
"versionCmd": "-v",
},
"php": {
"name": "PHP",
......@@ -60,7 +60,7 @@ var (
"printGrammar": "echo \"#\\n\";",
"interpreter": "C:\\php-7.3.9-Win32-VC15-x64\\php.exe",
"whereCmd": "where php",
"versionCmd": "%s -v",
"versionCmd": "-v",
},
"python": {
"name": "Python",
......@@ -69,7 +69,7 @@ var (
"printGrammar": "print(\"#\")",
"interpreter": "C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe",
"whereCmd": "where python",
"versionCmd": "%s --version",
"versionCmd": "--version",
},
"ruby": {
"name": "Ruby",
......@@ -78,7 +78,7 @@ var (
"printGrammar": "print(\"#\\n\")",
"interpreter": "C:\\Ruby26-x64\\bin\\ruby.exe",
"whereCmd": "where ruby",
"versionCmd": "%s -v",
"versionCmd": "-v",
},
"tcl": {
"name": "TCL",
......@@ -87,7 +87,7 @@ var (
"printGrammar": "set hello \"#\"; \n puts [set hello];",
"interpreter": "C:\\ActiveTcl\\bin\\tclsh.exe",
"whereCmd": "where tclsh",
"versionCmd": "echo puts $tcl_version;exit 0 | %s",
"versionCmd": "echo puts $tcl_version;exit 0",
},
}
......
package service
import (
"bytes"
"errors"
"fmt"
commConsts "github.com/aaronchen2k/deeptest/internal/comm/consts"
......@@ -10,7 +11,7 @@ import (
shellUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/shell"
"github.com/aaronchen2k/deeptest/internal/server/modules/v1/model"
"github.com/aaronchen2k/deeptest/internal/server/modules/v1/repo"
"os"
"os/exec"
"regexp"
"strings"
)
......@@ -103,15 +104,23 @@ func (s *InterpreterService) GetLangInterpreter(language string) (mp map[string]
}
path = strings.TrimSpace(output)
os.Setenv("ZTF_TMP_INTERPRETER", path)
cmd := fmt.Sprintf(versionCmd, "%ZTF_TMP_INTERPRETER%")
var cmd *exec.Cmd
if language == "tcl" {
cmd = exec.Command("cmd", "/C", versionCmd, "|", path)
} else {
cmd = exec.Command("cmd", "/C", path, versionCmd)
}
info, err = shellUtils.ExecWinCmd(cmd)
var out bytes.Buffer
cmd.Stdout = &out
err = cmd.Run()
if err != nil {
return
}
info = out.String()
arr := regexp.MustCompile("\r?\n").Split(info, -1)
for _, item := range arr {
item = strings.TrimSpace(item)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册