Expect script brokes when Ping file save

Hi,

For some reason I was needed to ping some URL and save the output to a file through Expect script, following is a very basic of that script, but it fails everytime. When I just copied the same 'ping' line to normal Terminal and run, it runs fine. Please, help.

#!/bin/sh

spawn ping -c 3 google.co.in > "/Users/SK/documents/newFile.txt"

interact

(Note: if I omit the part from '>' sign, then it works fine!)
Thanks!

Try it like this:

#!/usr/bin/expect -f
exec ping -c3 google.co.in > /Users/SK/documents/newFile.txt;