-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream_windows_386.go
More file actions
67 lines (62 loc) · 2.25 KB
/
Copy pathstream_windows_386.go
File metadata and controls
67 lines (62 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//go:build windows && 386
// +build windows,386
package stream
import (
"embed"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
)
//go:embed bin/stream-windows-386.exe
var binFiles embed.FS
func GetStream() (streamCmd string, tempFile string, err error) {
var errors []string
if path, lookErr := exec.LookPath("stream.exe"); lookErr == nil {
output, runErr := exec.Command(path).CombinedOutput()
if runErr == nil || strings.Contains(string(output), "STREAM") {
return path, "", nil
} else {
errors = append(errors, fmt.Sprintf("stream.exe 直接运行失败: %v\n输出: %s", runErr, string(output)))
}
} else {
errors = append(errors, fmt.Sprintf("无法找到 stream.exe: %v", lookErr))
}
tempDir, tempErr := os.MkdirTemp("", "streamWrapper")
if tempErr != nil {
return "", "", fmt.Errorf("创建临时目录失败: %v", tempErr)
}
binPath := "bin/stream-windows-386.exe"
fileContent, readErr := binFiles.ReadFile(binPath)
if readErr == nil {
tempFile = filepath.Join(tempDir, filepath.Base(binPath))
writeErr := os.WriteFile(tempFile, fileContent, 0755)
if writeErr == nil {
output, runErr := exec.Command(tempFile).CombinedOutput()
if runErr == nil || strings.Contains(string(output), "STREAM") {
return tempFile, tempFile, nil
} else {
errors = append(errors, fmt.Sprintf("%s 运行失败: %v\n输出: %s", tempFile, runErr, string(output)))
}
} else {
errors = append(errors, fmt.Sprintf("写入临时文件失败 (%s): %v", tempFile, writeErr))
}
} else {
errors = append(errors, fmt.Sprintf("读取嵌入的 stream 版本失败: %v", readErr))
}
return "", "", fmt.Errorf("无法找到可用的 stream 命令:\n%s", strings.Join(errors, "\n"))
}
func ExecuteStream(streamPath string, args []string) error {
var cmd *exec.Cmd
if streamPath == "stream.exe" {
cmd = exec.Command(streamPath, args...)
} else {
allArgs := append([]string{streamPath}, args...)
cmd = exec.Command("cmd", "/C", strings.Join(allArgs, " "))
}
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}