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

I do not believe that should be the case under normal Windows operation. 
Using a Sleep in a case like this is always a hack. Sometimes it is the 
only way, but it can fail randomly, especially under stress. There is 
likely something else going on. Could be poorly written antivirus software, 
or a finalizer that has not run in your go app, or something else. If it is 
ok for it to work "most of the time", then maybe your Sleep() solution is 
sufficient. But if you need real reliability, I suggest figuring out what 
is really going on. 

On Friday, August 14, 2020 at 10:10:44 AM UTC-4 atakanc...@gmail.com wrote:

> 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/b640dfba-2723-4601-a5f6-1fdd5ec7a965n%40googlegroups.com.

Reply via email to