Why can't I remove new line characters from being added with Node's exec function?
Problem
I have the following to execute shell commands using Node:
function puts( error, stdout, stderr ) {
stdout = sanitize( stdout ).rtrim("\n"); // remove new line
sys.puts( stdout );
}
I use this library to try and Remove new lines:
npm install validator
but when I do something like this:
exec( "ls -l", puts );
it puts a new line character on the end.
I'm using Linux
so the new line should just be a \n
right?!
How do I stop the new line from happening?
Many thanks.
Solution
Are you sure that the call to sys.puts isn't what's adding the newline? Try sys.print and see what you get.
In other news, I think that sys.puts (and sys in general) have been deprecated in node.js for a while. You should probably use console.log for this kind of thing.
Discussion
View additional discussion.