diff --git a/modules/gui/src/python_shell/python_shell_widget.cc b/modules/gui/src/python_shell/python_shell_widget.cc
index 5a86eb4184d75e2b25a493a80b5d09bae7b41962..efc07cbc38a1f0c5517c5c584883cae6fe3c1ade 100644
--- a/modules/gui/src/python_shell/python_shell_widget.cc
+++ b/modules/gui/src/python_shell/python_shell_widget.cc
@@ -612,6 +612,7 @@ QString PythonShellWidget::GetCommand()
   QTextCursor cursor(block_edit_start_);
   cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
   QString text= cursor.selectedText();
+  text.replace(QChar::LineSeparator,"\n");
   text.replace(QChar::ParagraphSeparator,"\n");
   return text;
 }