I would like to run a process in the background in Vim on Mac OS X (or Unix in general).
I would hope and expect the following, or some variant, to accomplish this:
execute "!my_command &"
or
!my_command &
or
!my_command \&
or some other alternative.
Unfortunately this does not seem to execute my_command at all. I would expect there to be some lightweight option.
One option would be to write a wrapper script that forks the command and exits, but I'm sure someone has done that already (GNU Parallel?).
What is the best way to accomplish this?
2 Answers
This might be because my_command needs a terminal to interact with. You could provide one with GNU screen or tmux, e.g.:
!screen -dm "my_command"
Or:
!tmux new -d "my_command"
All of the commands below work as expected when executed in MacVim (snapshot 66), and I'm pretty sure they would work on my Ubuntu box at home:
!mplayer song.mp3 &
:execute "!mplayer song.mp3 &"
:call system("mplayer song.mp3 &")
If it doesn't work for you, you could try one of the few scripts that allow you to run asynchronous commands:
(and I just saw that Thor solved your problem)