write_cmd and close in main.cpp