How to redirect Python print commands to putty SSH console?
<p>after many unsuccessful researches I've decided to ask my question here so maybe someone will provide me an answer or a lead for a problem I got.</p>

<p>I have a Python script that runs as a background process on an embedded device (the OS is a Linux distro). This script do important measurements and because of that, it can not be terminated or restarted.</p>

<p>I was wondering if it was possible to implement a chunk of code that will redirect the print() outputs to a Putty SSH console when we send it a command via a messaging protocol (MQTT).</p>

<p>So the situation will be like this:</p>

<ul>
<li>Device receive a command, set a variable to 1</li>
<li>Print() outputs will now be visible on the current root session opened by Putty SSH client.</li>
</ul>

<p>I don't know if it is possible but I'm opened to suggestions.</p>

<p>Thank you in advance for your answers, and sorry for my bad english.</p>

<p>As suggested by GhostCat, I've decided to go for a logging solution so anyone who can connect to the device by SSH can just "tail -F" the log file and see the debug messages.</p>

<p>I've removed all the print() statements in the code and replaced them by logging calls (which is, indeed, a more professional approach)</p>

<p>If someone had the same question as I, you can read this : <a href="http://www.blog.pythonlibrary.org/2014/02/11/python-how-to-create-rotating-logs/" rel="nofollow">http://www.blog.pythonlibrary.org/2014/02/11/python-how-to-create-rotating-logs/</a></p>

<p>or this : <a href="https://docs.python.org/2/howto/logging.html#logging-basic-tutorial" rel="nofollow">https://docs.python.org/2/howto/logging.html#logging-basic-tutorial</a></p>

<p>to help you solve your issue.</p>

<p>Thanks again to GhostCat and Tripleee for their help.</p>

python linux ssh putty