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

Windows: IO.popen closes pipe when forward slash in Typeperf command #3320

Open
NickMRamirez opened this issue Sep 11, 2015 · 11 comments
Open

Comments

@NickMRamirez
Copy link

On Windows, the following command, which starts a never-ending process that outputs performance metrics to the console, works with ruby 2.2.2, but fails with JRuby 9.0.0.0.pre2 (2.2.2):

IO.popen('typeperf "\Processor Information(*)\Interrupts/sec"') { |o| o.each { |line| puts line }}

In ruby, this command begins outputting performance metrics. However, with JRuby, I get:

Exiting, please wait...
Error: No valid counters.

I used the IRB to test ruby and then jruby -S irb to test JRuby. I believe it has to do with the forward slash. Other perfmon counters that do not have a slash work, for example:

IO.popen('typeperf "\Processor Information(*)\% Interrupt Time"') { |o| o.each { |line| puts line }}

Note that the forward slash is part of the counter's name and is within quotes, so it should not be counted as, for example, an argument to typeperf that begins with a forward slash.

@NickMRamirez
Copy link
Author

The popen method found in jruby/core/src/main/java/org/jruby/RubyIO.java. It calls into the Ruby19POpen class.

There's a block of code in the Ruby19POpen class that is changing forward slashes to back slashes. It may be doing it where it should not:

 if (Platform.IS_WINDOWS) {
  String commandString = _cmd.convertToString().toString().replace('/', '\\');
   _cmd = runtime.newString(commandString);
   if (_cmdPlusArgs != null) _cmdPlusArgs[0] = _cmd;
   } else {
      _cmd = _cmd.convertToString();
      if (_cmdPlusArgs != null) _cmdPlusArgs[0] = _cmd;
 }

For example, the forward slash in the following command should not be converted to a backslash:

typeperf "\Processor Information(*)\Interrupts/sec"

@nirvdrum
Copy link
Contributor

@NickMRamirez Can you try again with a newer version of JRuby 9.0.0.0 please? There were a lot of changes made since 9.0.0.0.pre2. The current release is 9.0.1.0.

@NickMRamirez
Copy link
Author

@nirvdrum I updated to jruby 9.0.1.0 (2.2.2) 2015-09-02 58f336. The problem still exists.

Running: jruby -S irb

And then:

IO.popen('typeperf "\Processor Information(*)\Interrupts/sec"') { |o| o.each { |line| puts line }}

Displays:
Exiting, please wait...
Error: No valid counters.

@erikpar
Copy link

erikpar commented Sep 16, 2015

Can i do any workaround for this problem?

@NickMRamirez
Copy link
Author

@erikpar Using Open3.popen3 seemed to work, but I couldn't get my unit tests to pass when I switched to using it. But in a pinch, you might try downloading and building the logstash-input-perfmon plugin and changing the call to IO.popen to use Open3.popen3 instead. Its usage isn't exactly the same, so you'd have to change things up a little, but only a little in the code around that call to IO.popen. Until jruby is fixed.

@erikpar
Copy link

erikpar commented Sep 24, 2015

Didn't managed to make it work

@NickMRamirez
Copy link
Author

@erikpar Since JRuby's IO.popen is buggy for Windows, I have changed the logstash-input-perfmon plugin to use Open3.popen3 instead. I will push to rubygems sometime soon, but you can get the source now.

@erikpar
Copy link

erikpar commented Sep 29, 2015

Thanks its working :-)

@samu
Copy link

samu commented May 4, 2016

This is still a problem in JRuby 9.0.5.0

@jsvd
Copy link
Contributor

jsvd commented Aug 3, 2018

I believe this is still an issue at least in 9.1.13.0:

irb(main):001:0> IO.popen("curl -v http://www.google.com")
=> #<IO:fd 100675>
* Rebuilt URL to: http:\\www.google.com/
* Port number ended with '\'
* Closing connection -1
curl: (3) Port number ended with '\'

@jsvd
Copy link
Contributor

jsvd commented Aug 3, 2018

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

No branches or pull requests

5 participants