Thank you for your reply. Unfortunately taskkill returns 128

buffer, err := exec.Command("my.exe", myArgs...).Output() // err is nil 
here, I get desired output 
_, err := exec.Command("taskkill", "/F", "/im", "my.exe").Output() // err 
is exit code 128, tried same with /pid, cmd.Process.Pid as well
os.Remove("my.exe") // remove "C:\\.......\my.exe": Access is denied  

14 Ağustos 2020 Cuma tarihinde saat 12:11:56 UTC+3 itibarıyla Tamás Gulácsi 
şunları yazdı:

> Windows locks the running program's file, you cannot delete it when it's 
> running - use "taskkill /F" to kill it proper.
>
> atakanc...@gmail.com a következőt írta (2020. augusztus 14., péntek, 
> 11:02:36 UTC+2):
>
>> 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/a93e0584-9eba-4e6c-aeac-389f0b31ed88n%40googlegroups.com.

Reply via email to