applescript work but application fails, why?

Hi,

i have developed applescript to quit applications (preview, acrobat reader and adobe reader) on the basis of process id.

when i run my script, it closes all above applications. But when i run an application (developed and saves as application from same script ) , it fails to do required and passes an error as follows:

sh: line 1:kill: 507
520: no such pid error no:1

Actually i missed to provide code line which will describe my problem fully.
the codeline to kill process of application are as :

				--set the_pid to (do shell script "ps ax | grep " & (quoted form of TempAppName) & " | grep -v grep | awk '{print $1}'")
				set the_pid to (do shell script ("ps -auxwww | grep " & (quoted form of theAppName) & " | grep -v grep | awk '{print $2}' "))
				if the_pid is not "" then do shell script ("kill -9 " & the_pid)

i even use the commented code line…but same output as
when applescript runs, 3 applications quits but when application runs, passes an error as above

what is the reason and the solution for the above error???

I call this application in my 4D Code to close this applications
please throw some light on it.

ukupatil
(India)

Browser: Safari 312
Operating System: Mac OS X (10.4)