HowTo.RunCommandInBackground History

Show minor edits - Show changes to markup

September 16, 2009, at 09:02 UTC by Allan Odgaard - Add info about detached commands
Added lines 1-19:

To have TextMate not stall when you run a command you need to:

 1. Create a subprocess (fork).
 2. Close stdout and stderr from your process.

In bash this is as simply as adding `&>/dev/null &` to your command.

In ruby we provide a wrapper which will fork and close stdout/err. In addition it will catch exceptions from your code block and show via an error dialog (these would normally be suppressed when you run stuff in the background).

Here is an example:

    #!/usr/bin/env ruby -KU
    require "#{ENV['TM_SUPPORT_PATH']}/lib/tm/detach"
    TextMate.detach do
      token = %x{"$DIALOG" nib --load RequestString}
      %x{"$DIALOG" nib --wait #{token}}
      %x{"$DIALOG" nib --dispose #{token}}
      raise "Done!"