Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.4
-
Fix Version/s: JRuby 1.7.0.pre1
-
Component/s: Core Classes/Modules
-
Labels:None
-
Environment:Mac OSX, Ubuntu Karmic
-
Testcase included:yes
-
Number of attachments :
Description
If you use a backtick operator, any data going through STDIN ends up going to that process during the time it is executing. Attached find an example that if you run it via:
cat test_file.txt | jruby test.rb
You will see "nil" whereas
cat test_file.txt | ruby test.rb
You will see "hello"
The reason for this is because of the presence of a `ls` on the first line of the script. Apparently STDIN gets corrupted due to this backtick.
Actually it appears to be even trickier than I first gave it credit for. It appears that in MRI ruby, if you use a backtick and the child process never reads STDIN, the script keeps STDIN. If the child process reads STDIN, it gets forwarded.
If you change the above example to `cat` instead of `ls`, then ruby and jruby have the same behavior. (You can verify this further by changing it to `cat > stdout.txt` which will then cause stdout.txt to contain the contents of the piped file into the script.)