[英]Golang os/exec not executing vscode portable
I'm attempting to launch vscode portable on Windows using a golang program.我正在尝试使用 golang 程序在 Windows 上启动 vscode 便携版。 I have the code unpacked and the data directory created.我已解压缩代码并创建了数据目录。 Launching code portable from command line seems to work fine (see below).从命令行启动可移植代码似乎工作正常(见下文)。
Here is what the code looks like:代码如下所示:
log.Printf("Launching code\n")
var pathtocode = filepath.Join(Home, "code")
codeSlice := [...]string{
pathtocode,
"--new-window",
"--remote",
fmt.Sprintf("ssh-remote+%s@%s", user, host),
"--wait",
fmt.Sprintf("%s/ws.code-workspace", remoteHome()),
}
cmd := exec.Command(codeSlice[0], codeSlice[1:]...)
cmd.Dir = Home
log.Println(cmd)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
err = cmd.Run()
if err != nil {
log.Fatal(err)
}
The execution fails with exit code 1 but there is no output at all: 2022/01/25 12:15:39 mydebug.go:138: exit status 1
执行失败,退出代码为 1,但根本没有 output: 2022/01/25 12:15:39 mydebug.go:138: exit status 1
If I copy the output from the Println and paste into command prompt it launches vscode portable and works as expected.如果我从 Println 复制 output 并粘贴到命令提示符中,它将启动 vscode 便携版并按预期工作。 C:\Users\me\.mydebug\vscode\code --new-window --remote ssh-remote+user@host --wait /home/user/ws.code-workspace
If I change the pathtocode to just "code" the program launches my installed vscode (in my path) and works using my installed version.如果我将 pathtocode 更改为“code”,程序会启动我安装的 vscode(在我的路径中)并使用我安装的版本工作。
I've tried a couple things (adding cmd /C, etc.), so far no love from vscode portable.我已经尝试了几件事(添加 cmd /C 等),到目前为止,vscode 便携版不喜欢。
I think I just figured it out.我想我刚刚想通了。 There is a Code.exe in the root of code portable which will launch code portable from the command line but there is also a file bin/code which also launches code portable.在可移植代码的根目录中有一个 Code.exe,它将从命令行启动可移植代码,但还有一个文件 bin/code 也可启动可移植代码。 If I use the bin/code file in the golang program it launches.如果我在它启动的 golang 程序中使用 bin/code 文件。
I don't know the reason for this but it seems to be working now.我不知道这是什么原因,但它现在似乎正在工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.