reload icon indicating copy to clipboard operation
reload copied to clipboard

Not supported by windows error

Open marioarizaj opened this issue 6 years ago • 14 comments
trafficstars

Hello. Thanks for writing this library, it is very useful. I am using these library for both my mac and linux versions of my cmd app. Unfortunately it looks like it does not support windows. Do you have any workaround for reloading in windows? Wish you all the best, Mario

marioarizaj avatar May 31 '19 08:05 marioarizaj

Do you get an error? Or what happens when you try to use it on Windows?

I don't have a Windows machine myself, so bit hard to look at it. The quickest way to get it running is to take a look at the code and see if you can fix it. It's not very complex so hopefully shouldn't be too hard.

arp242 avatar Jun 01 '19 00:06 arp242

Hello. Thanks for writing this library, it is very useful. I am using these library for both my mac and linux versions of my cmd app. Unfortunately it looks like it does not support windows. Do you have any workaround for reloading in windows? Wish you all the best, Mario

hello,did you find a solution? library not working for windows

0xhex avatar Feb 12 '20 11:02 0xhex

No @0xhex, I don't have a Windows machine to test myself, and the OP never got back with an error. What error are you getting?

arp242 avatar Feb 12 '20 11:02 arp242

No @0xhex, I don't have a Windows machine to test myself, and the OP never got back with an error. What error are you getting?

Here the error Screenshot 2020-02-12 14 31 40

0xhex avatar Feb 12 '20 11:02 0xhex

Thanks! It looks like syscall.Exec() isn't supported on Windows:

func Exec(argv0 string, argv []string, envv []string) (err error) {
    return EWINDOWS
}

Where EWINDOWS is the not supported by windows error.

I'm not sure what a good solution would be; I don't think there is an equivalent "replace current process" system call on Windows, although there probably are ways around it, see e.g. https://github.com/golang/go/issues/30662 as well as the same fix they did for kubectl.

Like I said, I don't really have a Windows machine so I can't test this, but happy to accept patches.

arp242 avatar Feb 12 '20 11:02 arp242

Thanks! It looks like syscall.Exec() isn't supported on Windows:

func Exec(argv0 string, argv []string, envv []string) (err error) {
    return EWINDOWS
}

Where EWINDOWS is the not supported by windows error.

I'm not sure what a good solution would be; I don't think there is an equivalent "replace current process" system call on Windows, although there probably are ways around it, see e.g. golang/go#30662 as well as the same fix they did for kubectl.

Like I said, I don't really have a Windows machine so I can't test this, but happy to accept patches.

I can provide you a dedicated server windows if you want,this is so important to me

0xhex avatar Feb 12 '20 11:02 0xhex

this code looks like working,i will back you about it

fmt.Println("test" + os.Args[0] + " __ " + os.Args[1])
time.Sleep(1 * time.Second)

cmd := exec.Command(os.Args[0], "0")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
cmd.Env = os.Environ()

err := cmd.Run()
if err == nil {
	os.Exit(0)
}

0xhex avatar Feb 12 '20 13:02 0xhex

Coolio, feel free to open a PR.

Not sure why that time.Sleep() is in there though? 🤔

arp242 avatar Feb 15 '20 10:02 arp242

Coolio, feel free to open a PR.

Not sure why that time.Sleep() is in there though? 🤔

Ah,i forgot to remove it 👍 i use it in my project before reload just waiting 1 second

0xhex avatar Feb 15 '20 10:02 0xhex

@0xhex thanks, the idea got me on the way, but a few things:

  • cmd.Run is blocking so the rest is not going to execute. cmd.Start is better
  • os.Exit(0) exits immediately the process. Instead I'm using something such as StopChan <- syscall.SIGINT to notify per signal and exits gracefully (and execute the remaining clean up functions). I'm not sure how this would integrate to this library as StopChan is part of my own program...

0cv avatar Mar 06 '20 10:03 0cv

Hi everyone! Any news on this?

I've tried this tool for cross build and it doesn't work on Windows =(

RedStalker avatar Sep 08 '20 13:09 RedStalker

I still don't have a Windows machine @RedStalker, so still waiting for a patch. In particular, need to be careful it replaces the process correctly and that no zombie processes are left behind.

arp242 avatar Sep 08 '20 13:09 arp242

any progress about it please?

0xhex avatar Feb 17 '21 10:02 0xhex

@arp242 That code will not replace the process, but rather spawn a new one and wait for it to exit. It's the best you can do for windows, since it doesn't support replacing a process.

@0cv The blocking behaviour is crucial, since the it's not meant to continue executing. Although, it should probably forward the exit code from the error:

cmd := exec.Command(os.Args[0], "0")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
cmd.Env = os.Environ()

err := cmd.Run()
if err == nil {
	os.Exit(0)
}
if exitError, isExit := err.(exec.ExitError); isExit {
	os.Exit(exitError.ExitCode())
}

os.Exit(1)

@0xhex It doesn't seem like you did a PR for this?

piksel avatar Mar 03 '21 11:03 piksel