Exec method adding extra quote at the end of variable

Anyone know how I can get around this problem? I am getting an extra
quote at the end of a variable called with the kernel::exec method.

I think the problem is because my variable looks like this:
‘file=@#{file}’ , where the ‘@’ is a necessary literal in the exec
command.

I have pasted the script and result here: http://pastebin.com/AktDLpNx

Any ideas how to get around this?

Thanks,
Jon