github.com/divyam234/rclone@v1.64.1/fs/log/redirect_stderr_windows.go (about) 1 // Log the panic under windows to the log file 2 // 3 // Code from minix, via 4 // 5 // https://play.golang.org/p/kLtct7lSUg 6 7 //go:build windows 8 // +build windows 9 10 package log 11 12 import ( 13 "log" 14 "os" 15 "syscall" 16 ) 17 18 var ( 19 kernel32 = syscall.MustLoadDLL("kernel32.dll") 20 procSetStdHandle = kernel32.MustFindProc("SetStdHandle") 21 ) 22 23 func setStdHandle(stdhandle int32, handle syscall.Handle) error { 24 r0, _, e1 := syscall.Syscall(procSetStdHandle.Addr(), 2, uintptr(stdhandle), uintptr(handle), 0) 25 if r0 == 0 { 26 if e1 != 0 { 27 return error(e1) 28 } 29 return syscall.EINVAL 30 } 31 return nil 32 } 33 34 // redirectStderr to the file passed in 35 func redirectStderr(f *os.File) { 36 err := setStdHandle(syscall.STD_ERROR_HANDLE, syscall.Handle(f.Fd())) 37 if err != nil { 38 log.Fatalf("Failed to redirect stderr to file: %v", err) 39 } 40 }