core: cleaner method of mirroring stdin for Windows

This commit is contained in:
Mitchell Hashimoto 2014-01-16 22:53:13 -08:00
parent a6be44125d
commit 2f4944903e
1 changed files with 7 additions and 18 deletions

View File

@ -176,28 +176,17 @@ module Vagrant
process.duplex = true if Platform.windows?
process.start
# We wait for the process in a thread because the IO.copy_stream
# below must happen from the main thread for some reason. It just
# hangs on other threads.
t = Thread.new do
process.wait
if Platform.windows?
# On Windows, the copy_stream below won't finish until we
# enter at least one more key. This asks the user to do that.
safe_puts
safe_puts("Press any key to exit.")
# On Windows, we have to mirror the STDIN to the child process.
while true
results = ::IO.select([$stdin], [], [], 0.5)
break if process.exited?
next if results[0].empty?
process.io.stdin.write(IO.read_until_block($stdin))
end
end
if Platform.windows?
begin
::IO.copy_stream(STDIN, process.io.stdin)
rescue Errno::EPIPE
end
end
t.join
process.wait if !process.exited?
return process.exit_code
end
end