Handling an empty return from "do shell script"

Here’s a little series of nested “if” statements use to filter some output. It works quite well when I click the “gofilter” button, but unfortunately, if there’s no match returned by do shell script, I receive an error “The Command Exited with a non-zero status.” So, I thought I would test for the presence of an answer by using grep -c to count the lines of the answer, if it’s blank, grep -c returns a 0 in standard output, but that results in the AppleScript error “0 (1)”

So you can see I’m trying to get the command to exit if there the output is less than 1 before actually populating the window.

On another note, how would one make it so that it would execute the search on the end editing theObeject handler? That doesn’t work for me either.

Here’s the code, called from on clicked theObject

on end editing theObject
	if the name of the window of theObject is "bomb" then
		if the name of theObject is "gofilter" then
			set searchTerm to (contents of text field "filter" of window "bomb")
			if searchTerm is not "" then
				set zerotest to do shell script "less < /tmp/bomb.txt|grep -ic " & quoted form of searchTerm
				if zerotest is equal to 0 then
				end if
				if zerotest is greater than 0 then
					set contents of text view "bomblist" of scroll view "package" of window "bomb" to do shell script "less < /tmp/bomb.txt|grep -i " & quoted form of searchTerm
				end if
			end if
		end if
	end if
end end editing

Browser: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7.8) Gecko/20050427 Camino/0.8.4
Operating System: Mac OS X (10.4)

Try this:

on end editing theObject
	set the_window to window of theObject
	if name of the_window = "bomb" and name of theObject is "gofilter" then
		set searchTerm to (contents of text field "filter" of the_window)
		if searchTerm is not "" then
			try
				set zerotest to (do shell script "less < /tmp/bomb.txt | grep -ic " & quoted form of searchTerm)
				set contents of text view "bomblist" of scroll view "package" of the_window to zerotest
			on error e
				log e
			end try
		end if
	end if
end end editing

Jon