The problem might be the interaction of ps with termcap/terminfo. It
seems your ps accepts BSD-style options. Are you on Mac OS X? I do not
know what terminal information, if any, irb/ruby provide to their
children processes. If they do provide such information, say in the
TERM environment variable, ps will try to get obtain the terminal width
and truncate its output to fit. On my GNU/Linux system with Ruby 1.8.5,
forcing a wide display (using SYSV style arguments) works:
This is tricky: you are not guaranteed that grep will be already lanched by the time ps reads the process table. If you try that several times on the command-line, you’ll find that some times it doesn’t find grep.
irb(main):026:0> r = ps efxl |grep "grep"
=> “”
irb(main):027:0> puts r
=> nil
irb(main):028:0>
The problem seems to be with the pipe character | but escaping it
with"" has no effect.
How can put a “|” inside my backticks?
It has nothing to do with the |. The problem is, maybe when run under ruby, the timing is slightly different, and you come up more often with the case when grep is not started yet. See this: