[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

system() bug



Hello all.

I am using a piece of software called irexec() which comes with lirc (remote 
control), and I wanted that when I press a button on my remote control it 
will oopne xawtv and when I press it again it will close it (the power 
button).

I wrote a script, which does work under pure bash, but when executed in 
irexec, it does not work - it does not redirect some output to to a tmp file 
which is needed to kill/close that wanted program. The funny part comes when 
I change the system() line in irexec to some exec("/usr/bash") line. it 
redirects the output very good (but then it closes the irexec program...). 
the bash i have is 2.04  from mandrake 7.2.


I have attached the script (if anybody here finds a bug on it I will be very 
glad to know it). here are some examples of how to use the script:

1) "run-kill xawtv xawtv-remote close" (for closing it will call xawtv-remote 
close)
2) "run-kill xmms" (for closing it will call kill <the progress ID of xmms>)


  - diego
  
#/bin/sh!

MAIN_PROG=$1
PROGRAM_TO_RUN=`which $1`

if [ -f  /tmp/$MAIN_PROG.flag.run ] ; then
  echo killing progarm... $1
  KILLING_COMMAND=`cat /tmp/$1.flag.run`
  rm -f /tmp/$1.flag.run
  echo Now killing: command = $KILLING_COMMANDs
  exec $KILLING_COMMAND
else
  if [ -f $PROGRAM_TO_RUN ] ; then
    echo Executing program "$PROGRAM_TO_RUN"

    $PROGRAM_TO_RUN > nul &

    if [ "$2" == "" ] ; then
      PROGRAM_PID=`/sbin/pidof $1`
      KILL_COMMAND="/bin/kill $PROGRAM_PID"
    else
      KILL_COMMAND="$2 $3 $4 $5 $6 $7 $8 $9"
    fi

    echo Closing command: "$KILL_COMMAND",  will be written in "/tmp/$MAIN_PROG.flag.run"
    touch /tmp/$MAIN_PROG.flag.run
    echo $KILL_COMMAND > /tmp/$MAIN_PROG.flag.run

  else
    echo kill-run [program-name]
    echo
    echo Use to run and kill a program from the console.
    echo
  fi
fi