Hello guys, I have solved the issue.

Turns out it takes some time to release the lock on the folder, so we 
should do some time.Sleep before the os.Remove, so that Windows can release 
the lock. 

Thank you both for replying.

14 Ağustos 2020 Cuma tarihinde saat 16:21:17 UTC+3 itibarıyla 
jake...@gmail.com şunları yazdı:

> This works fine for me on Windows 10. 
> What is "my.exe" doing? 
> Do you have third party antivirus software? If so, try turning it off. 
> They are notorious for causing this kind of problem. 
>
> On Friday, August 14, 2020 at 5:02:36 AM UTC-4 atakanc...@gmail.com wrote:
>
>> Hello dear fellow gophers, 
>>
>> I had a relatively simple yet quite inconvenient issue which I felt the 
>> need to ask here. In my main() function;
>>
>> os.Remove("my.exe") // err is nil, my.exe is removed
>>
>> works in Windows without any errors, but when I call exec beforehand, I 
>> get access is denied error;
>>
>> buffer, err := exec.Command("my.exe", myArgs...).Output() // err is nil 
>> here, I get desired output
>> os.Remove("my.exe") // remove "C:\\.......\my.exe": Access is denied
>>
>> I tried using cmd.Process.Kill(), cmd.Process.Wait(), 
>> cmd.Start()-ioutil.ReadlAll()-cmd.Wait() alternatives as well. I kept 
>> getting no errors until 'Access is denied'. 
>>
>> I'm using go1.14 linux/amd64 for my compiler and Windows 10 Enterprise 
>> 10.0.18362.
>>
>> Thank you.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/abdea61e-5166-4cb7-ab5a-3443ca6da129n%40googlegroups.com.

Reply via email to