some command line work. don't know why it outputs undefined when writing file