exec.Command with spaces in folder or filename - os=windows

i must execute a file under C:\Program Files (x86)\appfolder\appname.exe
i try this:
myApp := " + os.Getenv(“PROGRAMFILES(X86)”) + \appfolder\appname.exe"
myApp looks then like this:
“C:\Program Files (x86)\appfolder\appname.exe”
now i try to execute the app with
cmd := exec.Command(myApp)
err := cmd.Run
if err != nil {
log.Fatal(err)
}

the error output ist:
exec: “"C:\Program Files (x86)\appfolder\appname.exe”": file does not exist
I dont know why GO add "\ at the bein oft my variable.
using cmd.Dir := os.Getenv(“PROGRAMFILES(X86)”) + \appfolder\appname.exe does also niot work.

Hopeful that some can help me
regards

I think yiu need to add double “\\” in your myApp variable, so

myApp := os.Getenv("PROGRAMFILES(X86)") + \\appfolder\\appname.exe"`

Hello Yamil, first of all, thank you for your help.
unfortunately this solution does not work either. I have temporarily solved the problem by calling a Windows batch file.
Now I have found another problem with spaces in a directory name. I am trying to use the Windows command xcopy.exe to copy a directory that contains spaces.
Example:

srcFolder := " + ”C:\My Temp Folder\.” + "
desFolder := “C:\NewFolder\.
command := “xcopy.exe ‘ + srcfolder + ’ ‘ + destFolder + ’ /s /y”
cmd := exec.Command(“cmd”, “/C”, command)
output, err := cmd.Output()
if err != nil {
res = false
}
command looks like this:
xcopy.exe “C:\My Temp Folder*.” C:\NewFolder*. /s /y but no files are copied.
xcopy.exe: 0 file(s) copied.
If I enter the content of command in a Windows cmd window it works.

Many thanks for any help
Matthias

Translated with DeepL.com (free version)

I think you should try []string args, not a string?

thanks. :slight_smile:
I try it with arg, but dont work. :frowning:
i looking now for a other solution to copy a directory with all files and subfolder.

You can try this package GitHub - emar-kar/copy: Simple copy module for go applications