From 968e3537b63c119f69bd37f71347b14fe8699c4d Mon Sep 17 00:00:00 2001 From: simonzhangsz Date: Wed, 30 Aug 2023 16:58:26 +0800 Subject: [PATCH] wasm change --- .gitignore | 3 +++ .vscode/launch.json | 19 +++++++++++++++++- .vscode/settings.json | 8 ++++++++ lib/run/exec_wasm.go | 45 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 lib/run/exec_wasm.go diff --git a/.gitignore b/.gitignore index 43b1de48..8d34e80f 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ crontask/database/ crontask/export/ crontask/temp crontask/crontask +crontask/__debug_bin.exe restagent/backup/ restagent/log/ @@ -23,11 +24,13 @@ restagent/upload/ restagent/software/ restagent/database/ restagent/restagent +restagent/__debug_bin.exe sshsvc/sshsvc sshsvc/mmllog/ sshsvc/mmlhome/ sshsvc/log/ +sshsvc/__debug_bin.exe tools/loadmconf/loadmconf diff --git a/.vscode/launch.json b/.vscode/launch.json index b2a7dbee..1c3fceb8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,7 @@ // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { "name": "调试模式", "type": "go", @@ -11,6 +12,22 @@ "mode": "debug", "program": "./restagent/restagent.go", "console": "integratedTerminal" - } + }, + { + "name": "调试模式restagent", + "type": "go", + "request": "launch", + "mode": "debug", + "program": "d:/local.git/ems.agt/restagent/restagent.go", + "console": "integratedTerminal" + }, + { + "name": "debug sshsvc", + "type": "go", + "request": "launch", + "mode": "debug", + "program": "d:/local.git/ems.agt/sshsvc/sshsvc.go", + "console": "integratedTerminal" + } ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 351b8eaf..d844704b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,11 @@ { + "go.toolsEnvVars": { + "GOARCH": "amd64", + "GOOS": "windows" + }, + "go.testEnvVars": { + "GOARCH": "wasm", + "GOOS": "js" + }, "commentTranslate.hover.enabled": true } \ No newline at end of file diff --git a/lib/run/exec_wasm.go b/lib/run/exec_wasm.go new file mode 100644 index 00000000..cf5bfd5a --- /dev/null +++ b/lib/run/exec_wasm.go @@ -0,0 +1,45 @@ +//go:build wasm +// +build wasm + +package run + +import ( + "os/exec" + + "ems.agt/lib/log" +) + +func ExecCmd(command, path string) ([]byte, error) { + log.Debug("Exec command:", command) + + cmd := exec.Command("cmd", "/C", command) + cmd.Dir = path + out, err := cmd.CombinedOutput() + log.Tracef("Exec output: %v", string(out)) + if err != nil { + log.Error("exe cmd error: ", err) + return out, err + } + + return out, nil +} + +func ExecOsCmd(command, os string) error { + log.Debugf("Exec %s command:%s", os, command) + + var cmd *exec.Cmd + switch os { + case "Linux": + cmd = exec.Command(command) + case "Windows": + cmd = exec.Command("cmd", "/C", command) + } + + out, err := cmd.CombinedOutput() + log.Tracef("Exec output: %v", string(out)) + if err != nil { + log.Error("exe cmd error: ", err) + return err + } + return nil +}