Make sure to escape the following characters as well: NULL (ascii 0) \n (newline) \r (carriage return) \ ' " CTRL-Z _ % You may also want to look at escaping [TAB] as well