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