I'm not sure why that isn't working for you, but I would recommend a different approach to keep as much code out of your ERB as possible. It's best to use ERB for expression evaluation, simple looping and/or control flow. Other than that, I'd put everything else (where possible) in the Puppet manifest.
You can do something like this:
# In manifest.pp...
$mytext = generate('/path/to/command')
# In myfile.txt.erb...
<%= @mytext -%>
Give that a try and post back here if it works for you or not.
generate function does some rudimentary checking for legal characters because it does not invoke a shell. If you need to do some more advanced things, then you can spawn a shell yourself like so:
$java_home = generate('/bin/sh', '-c', '/bin/readlink -f $(which java)| sed "s/bin\/java//"')
Hope that helps.