开发者

How to get output to show up in cmd window during Ruby script running (Windows 7)

ruby 1.9.2 watir 1.8.1

We start our ruby script from the cmd prompt (driver.rb). The ruby script then performs the following line to execute a cmd prompt command:

response = `choice /c 12 /n /m "1. Qual -- 2. Test"`

I would like the prompt window to display the choice to allow the user to make the selection and then return the selection.

When the command is executed, the message is not displayed but the cmd window is waiting for a response.

When I enter the value (1 or 2), it returns the string

(/c 12 /n /m "1. Qual -- 2. Test x) 

with x being the 开发者_如何学编程value I chose.

When the ruby script is done executing, then I see the prompt in the cmd window.

When we run, any output from the ruby script (e.g. puts) shows up after the script has ended.

Is there a way to have the output go to the cmd window while ruby is running and not wait until is has ended or at least have the cmd prompt command show up?

I would appreciate any help in this matter.


If you are requiring or including other ruby scripts, the code in those scripts gets executed. That's not a problem if all they do is define classes, methods, etc. However if there is actual code in those files which is not part of defining an object or method, it'd going to execute, ahead of any other flow control etc in your main script.

I can't say for sure if that's what is happening to you, but it sounds like it might be the case depending on how you are trying to structure things.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜