On 10/17/2012 09:17 PM, jorelli wrote:
> Perhaps I am doing something wrong, but I have been playing with this for the past hour or so and
> I'm of the opinion that something, somewhere, is broken with regards to killing child processes, at
> least on OS X. I am able to consistently crash my computer using os.Process.Release().
>
> I have a solution that I believe should work in theory, but in practice the results are rather
> inconsistent. It may work on your machine, but I can't get it to work consistently on mine;
> sometimes it works cleanly, sometimes it doesn't.
>
> Use cmd.Start() instead of cmd.Run(). This will start the command but not wait for it. To wait
> for the command to finish, you can use cmd.Wait().
>
> Instead, if the command is running and you want to abort it, use cmd.Process.Kill() to end the
> command. As for doing it with timeout handling, it's pretty straightforward go concurrency
> patterns; run the command in one goroutine and send a signal when it's finished, have another
> goroutine send a signal on a timeout, and use a select statement to chose the event that happens
> first. The result on my machine is that sometimes the resources are freed properly, sometimes they
> aren't; that typically signals some kind of subtle race condition that I can't spot.
>
> Here's a gist of a partial solution:
https://gist.github.com/3907512
>
> if you're running this in some other shell and you don't care that it mangles the TTY because it's
> not a login shell, then that'll work. For me, I can't get a healthy shell to return from that.
>
>
> On Wednesday, October 17, 2012 3:43:06 AM UTC-4, (unknown) wrote:
>
> Hello.
>
> The sample code will try to execute git clone a non-existent repo from github.
> The command will output "Username for '
https://github.com':" and wait for user
> input.
>
> Sample code:
http://play.golang.org/p/rY77eJs0Z9 <
http://play.golang.org/p/rY77eJs0Z9>
>
> Is there a simple way to terminate an executed command if it's waiting for
> standard input.
>
> If I try to execute "cat" it will terminate by itself if cmd.Stdin is not set to
> os.Stdin.
>
> Any thoughts on the matter are appreciated.
>
>
> Cheers /u
>
Thank you for all the replies. I would like to give you some background about
what I'm trying to accomplish.
Basically I would like to evaluate if an import path is downloadable through
"go get".
Imagine if you could systematically check all import paths listed at
http://go.pkgdoc.org/-/index and label them, based on if they are "go-getable".
Being able to filter the import paths on
pkgdoc.org based "CanGet" (go getable)
and "CanBuild" would be interesting, making the list more convenient to use.
I've uploaded a simple test case for those who want to try it out:
go get
github.com/mewmew/status/cmd/gos
I tried to make the first sample as minimal as possible. The command I'm
actually running is "go get -d" (only download), which in turn executes git
clone.
It will download the provided import path, and all it's import dependencies. If
the import path or one of it's dependencies result in a 404, the "go get"
command will output "Username for..." and wait for user input.
That is the thing I want to find a clean solution to. Killing the "go get"
command based on a timeout would not work for large projects (possibly with many
dependencies), since they should take a longer time to download.
These are the things I've been playing around with, so far without any succes:
* Close os.Stdin before executing "go get".
* Use a fake io.Reader for cmd.Stdin with a Read method that always returns
io.EOF
I would like to stay away from specific solutions if possible, such as scanning
standard output for "Username for..." before killing the "go get" command.
Any and all suggestions are welcome :)
cheers /u