Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not supported by windows error #7

Open
marioarizaj opened this issue May 31, 2019 · 14 comments
Open

Not supported by windows error #7

marioarizaj opened this issue May 31, 2019 · 14 comments

Comments

@marioarizaj
Copy link

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

@arp242
Copy link
Contributor

arp242 commented Jun 1, 2019

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.

@0xhex
Copy link

0xhex commented Feb 12, 2020

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

@arp242
Copy link
Contributor

arp242 commented Feb 12, 2020

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?

@0xhex
Copy link

0xhex commented Feb 12, 2020

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

@arp242
Copy link
Contributor

arp242 commented Feb 12, 2020

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.

@0xhex
Copy link

0xhex commented Feb 12, 2020

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
Copy link

0xhex commented Feb 12, 2020

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)
}

@arp242
Copy link
Contributor

arp242 commented Feb 15, 2020

Coolio, feel free to open a PR.

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

@0xhex
Copy link

0xhex commented Feb 15, 2020

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

@0cv
Copy link

0cv commented Mar 6, 2020

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

@RedStalker
Copy link

Hi everyone! Any news on this?

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

@arp242
Copy link
Contributor

arp242 commented Sep 8, 2020

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.

@0xhex
Copy link

0xhex commented Feb 17, 2021

any progress about it please?

@piksel
Copy link

piksel commented Mar 3, 2021

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants