Continue execution of bash script while in listening state

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Continue execution of bash script while in listening state

Postby leke » Wed May 26, 2010 7:51 pm

I wanted to automate a fairly long shell script process that kind of falls in to a listening state and then would need to open another window and execute another command. Problem is, I don't know how to run other commands after that state is reached.

Any tips?
Thanks.

Here is the script if you are interested...
Code: Select all
hciconfig reset
sdptool add --channel=2 SP
# Connect phone's bluetooth console to PC then...

rfcomm listen rfcomm2 2
# Connection is made. Process is ongoing.

# This would open new terminal if the last command wasn't still running.
gnome-terminal -e 'cu -l /dev/rfcomm2'
User avatar
leke
LXF regular
 
Posts: 508
Joined: Mon Oct 22, 2007 5:45 pm
Location: Oulu, Finland

Postby nelz » Wed May 26, 2010 8:07 pm

You could use a fifo, which works rather like a pipe but looks like a file. Something like

Code: Select all
mkfifo /tmp/myfifo
command1 >/tmp/myfifo &

cat /tmp/myfifo | while read stuff; do
    process stuff
    done


The & on command1 backgrounds the process. Then your loop runs until command1 exits and it has read all data in the pipe.
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8579
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby leke » Fri May 28, 2010 12:04 pm

Thanks. I've still trying to understand how it works, but thanks for the info :P I'll do some googling on the subject ;)
User avatar
leke
LXF regular
 
Posts: 508
Joined: Mon Oct 22, 2007 5:45 pm
Location: Oulu, Finland


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests