I'd gladly comment on the question, but stackexchange "rep" policies do not allow me to comment. Therefore I drafted this "answer". Please bear with me! This answer aims to prevent you from going into the wrong direction.
If you open a terminal console and enter
pmset -g pslog, you see what happens when you close the lid:
mc-dondon:~ dondon$ pmset -g pslog
Logging IORegisterForSystemPower sleep/wake messages
pmset is in logging mode now. Hit ctrl-c to exit.
16.11.13 01:28:57 MEZ
Currently drawing from 'AC Power'
-InternalBattery-0 55%; charging; (no estimate)
16.11.13 01:29:02 MEZ IORegisterForSystemPower: ...Sleeping...
If you google, you'll find a lot of pages which claim that pmset would do the trick. However, with respect to your question, pmset does not do the trick - at least not for me.
Neither "sudo pmset noidle" nor the often suggested "sudo pmset -a lidwake 0" will prevent the system to go to sleep when the lid is closed.