wasm change

This commit is contained in:
2023-08-30 16:58:26 +08:00
parent b8d5c7c2f8
commit 968e3537b6
4 changed files with 74 additions and 1 deletions

3
.gitignore vendored
View File

@@ -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

17
.vscode/launch.json vendored
View File

@@ -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"
}
]
}

View File

@@ -1,3 +1,11 @@
{
"go.toolsEnvVars": {
"GOARCH": "amd64",
"GOOS": "windows"
},
"go.testEnvVars": {
"GOARCH": "wasm",
"GOOS": "js"
},
"commentTranslate.hover.enabled": true
}

45
lib/run/exec_wasm.go Normal file
View File

@@ -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
}