[TxMt] Starting a background process from a command

Daniel Grady d.c.grady at gmail.com
Thu Nov 4 13:30:02 UTC 2010


Hi everyone, I'm trying to write a TM command that will set up some FIFOs, launch a process connected to those, and then the command will exit, the idea being that other commands can subsequently talk to the running process using the named pipes.

In my case I'm trying to set up communications with MATLAB; I have to use it for work, but I'm no great fan of the interface and spend most of my time writing scripts with TM instead, so this is just trying to take it to the next level. I see that this same thing has been brought up a few times before on the mailing list, and that the approach using named pipes is the usual suggestion. However, when I try to implement this inside a TM command, the command doesn't exit until the launched process also exits.

Inside a testing directory, I have test_script.sh:

pwd

mkfifo in
mkfifo out

nohup bash -s < in &> out &
bashpid=$!

# disown $bashpid
echo $bashpid

echo Done

When I run this script from Terminal, everything works as expected: a new bash gets started up in the background, its parent is launchd, I can pass in commands and read output from the in and out pipes, and it persists even if I close Terminal.

Now if I put the same script inside a TM command and then run the command inside a file (which is saved in the same testing directory), the command hangs until I go pipe 'exit' or something into in and read from out. I would expect the command to immediately exit; does anyone know why it doesn't? Thanks in advance!

-Daniel



More information about the textmate mailing list