Only invoke print if there is something to be printed

This allows MATLAB commands to be called in situations where a task
switch would not be safe.