exec() in BeanShell macro causes jEdit to hang when it returns non-zero exit code
- by rossmeissl
I have a jEdit BeanShell macro that runs my Markdown files through Maruku when I save them:
if (buffer.getMode().toString().equals("markdown")) {
cmd = "C:\\Ruby\\bin\\maruku.bat -o " + buffer.getDirectory() + buffer.getName().replaceAll("markdown$", "html") + " " + buffer.getPath();
exec(cmd);
}
This works great when the Markdown file is valid. But if I've made a mistake, jEdit just waits around forever for the exec() call to "succeed," which it never will. When this happens, I have to kill jEdit's javaw.exe process and run Maruku manually from the command line to discover the error, e.g.:
E:\bp\plan\supply_chain>maruku business_plan.markdown
___________________________________________________________________________
| Maruku tells you:
+---------------------------------------------------------------------------
| Could not find ref_id = "17" for md_link(["17"],"17")
| Available refs are []
+---------------------------------------------------------------------------
!C:/Ruby/lib/ruby/gems/1.8/gems/maruku-0.6.0/lib/maruku/errors_management.rb:49:in `maruku_error'
!C:/Ruby/lib/ruby/gems/1.8/gems/maruku-0.6.0/lib/maruku/output/to_html.rb:716:in `to_html_link'
!C:/Ruby/lib/ruby/gems/1.8/gems/maruku-0.6.0/lib/maruku/output/to_html.rb:970:in `send'
!C:/Ruby/lib/ruby/gems/1.8/gems/maruku-0.6.0/lib/maruku/output/to_html.rb:970:in `array_to_html'
!C:/Ruby/lib/ruby/gems/1.8/gems/maruku-0.6.0/lib/maruku/output/to_html.rb:961:in `each'
\___________________________________________________________________________
Not creating a link for ref_id = "17".
Then I restart jEdit, fix the error, and re-save the file, at which point the macro succeeds.
How can I make my macro more resilient to either die helpfully (display Maruku's error output) or, at the very least, die silently so I don't have to kill jEdit?