Terminate a shell script that is in a loop?
===

We have a terminal command(test) that monitors specific network traffic, so it runs itself in a loop to continuously pick up new data. We are running 'test' in a Cocoa application via NSAppleScript, and in a separate thread, since it runs in a loop we wouldn't be able to process any other methods if it was run from the main thread.

After the command begins to run we pipe the output to a file, and then we have a loop going in Cocoa that reads the file every second to pick up new data and displays the file's contents in NSScrollView.

After we stop the read/output loop, the NSAppleScript command still continues to run, and place information in the file. How do we stop that command from running? When running the command via terminal "ctrl-c"/"cmd-c" stops it, if we were to input that using another NSAppleScript, how would we get it to enter into the window that our monitoring command is running in.

e.x.
    
    NSString *testCommand = @"do shell script\"testMonitor >> ~/Desktop/stuff.txt\"";
    
    NSAppleScript *enableScript = [[NSAppleScript alloc] initWithSource:testCommand];
    
    enableScript executeAndReturnError:nil];

Is the method that runs in its own thread.
The looping 'showOutput' method is reading stuff.txt and sending it to NSScrollView so that we can read it. The issue is after we stop 'showOutput', testMonitor continues to run, which we noted by viewing additional output to stuff.txt.

Is there any way to stop the command, would stopping the thread stop the command? How might we accomplish either of the things, new ideas would be great.

-Much appreciated.