edgex004
Advanced Member
- Joined
- Jan 5, 2008
- Messages
- 1,222
I have been working for a while to get a pre and post script working that will shutdown QJoyPad as I start the PND, and then turn it back on as I quit, but only if it was running in the first place.
This is what I have written:
PND_pre_script.sh
#!/bin/bash
if [ ! "$EXENAME" = "../../../usr/bin/links" ]; then
# Stop Qjoypad
killall qjoypad
KILLMARKER="$?"
QJOYKILLED="/home/edged/joykilled"
if [ "$KILLMARKER" == "0" ]; then
echo "YES" > $QJOYKILLED
else
echo "NO" > $QJOYKILLED
fi
fi
PND_post_script.sh
#!/bin/bash
if [ ! "$EXENAME" = "../../../usr/bin/links" ]; then
# Restart Qjoypad
QJOYKILLED="/home/edged/joykilled"
KILLMARKER=`cat $QJOYKILLED`
if [ "$KILLMARKER" == "YES" ]; then
notify-send "QJoyPad Started"
echo "NO" > $QJOYKILLED
nohup pqr qjoypad > /dev/null 2>&1 &
fi
fi
At the moment, the scripts seem to run fine on their own, but when they are run by the PND, they have some funny behavior.
The behavior looks like this:
1. Run QJoyPad
2. Run PND with the aforementioned pre and post scripts. Qjoypad is killed.
3. Exit PND, and QJoyPad starts again.
4. Run PND again, and now QJoyPad is both killed and restarted prior to PND launch. **Notification from the post script is once again displayed prior to the PND starting.**
5. Exit the PND again, and now QJoyPad is not restarted.
Adding an "exit" line after "nohup pqr qjoypad > /dev/null 2>&1 &" will cause the first run to work okay, but then the second run will have error number 4, but then QJoyPad will continue to run during and after the PND is run.
I suspect that for some reason, launching a separate PND in the background from within a post script causes that post script to run again prior to the launch of other PNDs. Or something.
If the scripts are assigned to multiple PNDs, you can run first.pnd just fine, but then the second.pnd will exhibit the incorrect behavior if it is run afterward.
Honestly I have been pouring over this and just can't figure out what is going wrong. I know my methodology is crummy, but I've just been trying various different methods to see if I can get it to work before I try to make the code have decent error handling.
Any help would be greatly appreciated.
This is what I have written:
PND_pre_script.sh
#!/bin/bash
if [ ! "$EXENAME" = "../../../usr/bin/links" ]; then
# Stop Qjoypad
killall qjoypad
KILLMARKER="$?"
QJOYKILLED="/home/edged/joykilled"
if [ "$KILLMARKER" == "0" ]; then
echo "YES" > $QJOYKILLED
else
echo "NO" > $QJOYKILLED
fi
fi
PND_post_script.sh
#!/bin/bash
if [ ! "$EXENAME" = "../../../usr/bin/links" ]; then
# Restart Qjoypad
QJOYKILLED="/home/edged/joykilled"
KILLMARKER=`cat $QJOYKILLED`
if [ "$KILLMARKER" == "YES" ]; then
notify-send "QJoyPad Started"
echo "NO" > $QJOYKILLED
nohup pqr qjoypad > /dev/null 2>&1 &
fi
fi
At the moment, the scripts seem to run fine on their own, but when they are run by the PND, they have some funny behavior.
The behavior looks like this:
1. Run QJoyPad
2. Run PND with the aforementioned pre and post scripts. Qjoypad is killed.
3. Exit PND, and QJoyPad starts again.
4. Run PND again, and now QJoyPad is both killed and restarted prior to PND launch. **Notification from the post script is once again displayed prior to the PND starting.**
5. Exit the PND again, and now QJoyPad is not restarted.
Adding an "exit" line after "nohup pqr qjoypad > /dev/null 2>&1 &" will cause the first run to work okay, but then the second run will have error number 4, but then QJoyPad will continue to run during and after the PND is run.
I suspect that for some reason, launching a separate PND in the background from within a post script causes that post script to run again prior to the launch of other PNDs. Or something.
If the scripts are assigned to multiple PNDs, you can run first.pnd just fine, but then the second.pnd will exhibit the incorrect behavior if it is run afterward.
Honestly I have been pouring over this and just can't figure out what is going wrong. I know my methodology is crummy, but I've just been trying various different methods to see if I can get it to work before I try to make the code have decent error handling.
Any help would be greatly appreciated.
Last edited by a moderator: