'Golang os/exec not executing vscode portable

I'm attempting to launch vscode portable on Windows using a golang program. 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

If I copy the output from the Println and paste into command prompt it launches vscode portable and works as expected. 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.

I've tried a couple things (adding cmd /C, etc.), so far no love from vscode portable.



Solution 1:[1]

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. If I use the bin/code file in the golang program it launches.

I don't know the reason for this but it seems to be working now.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mikedoy