Tuesday, April 29, 2025
HomeGolangexec.Command with areas in folder or filename - os=home windows - Getting...

exec.Command with areas in folder or filename – os=home windows – Getting Assist


i have to execute a file underneath C:Program Information (x86)appfolderappname.exe
i do this:
myApp := " + os.Getenv(“PROGRAMFILES(X86)”) + appfolderappname.exe"
myApp appears then like this:
“C:Program Information (x86)appfolderappname.exe”
now i attempt to execute the app with
cmd := exec.Command(myApp)
err := cmd.Run
if err != nil {
log.Deadly(err)
}

the error output ist:
exec: “”C:Program Information (x86)appfolderappname.exe””: file doesn’t exist
I dont know why GO add ” on the bein oft my variable.
utilizing cmd.Dir := os.Getenv(“PROGRAMFILES(X86)”) + appfolderappname.exe does additionally niot work.

Hopeful that some may also help me
regards

I feel yiu want so as to add double “” in your myApp variable, so

myApp := os.Getenv("PROGRAMFILES(X86)") + appfolderappname.exe”`

Hi there Yamil, to begin with, thanks to your assist.
sadly this resolution doesn’t work both. I’ve quickly solved the issue by calling a Home windows batch file.
Now I’ve discovered one other drawback with areas in a listing title. I’m attempting to make use of the Home windows command xcopy.exe to repeat a listing that accommodates areas.
Instance:

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 appears like this:
xcopy.exe “C:My Temp Folder*.” C:NewFolder*. /s /y however no recordsdata are copied.
xcopy.exe: 0 file(s) copied.
If I enter the content material of command in a Home windows cmd window it really works.

Many thanks for any assist
Matthias

Translated with DeepL.com (free model)

I feel it is best to attempt []string args, not a string?

thanks. :slight_smile:
I attempt it with arg, however dont work. :frowning:
i trying now for a different resolution to repeat a listing with all recordsdata and subfolder.

You possibly can do this bundle GitHub – emar-kar/copy: Easy copy module for go functions

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments