title: Why can't I redirect stdout of a python script to a file
body: <p>I am starting my service running on a Raspberry Pi 2 (Raspbian) using a command in <code>rc.local</code> which looks like this:</p>
  
  <pre><code>python3.4 /home/pi/SwitchService/ServiceStart.py &gt;/home/pi/SwitchService/log &amp;
  python3.4 /home/pi/test.py &gt;/home/pi/log2 &amp;
  </code></pre>
  
  <p>For some reason I don't see any text in the log file of my service although the script prints to stdout.</p>
  
  <p>the two scripts look like this:</p>
  
  <p><strong>test.py</strong></p>
  
  <pre><code>print("Test")
  </code></pre>
  
  <p><strong>ServiceStart.py</strong></p>
  
  <pre><code>from Server import Server
  print("Test")
  if __name__ == "__main__":
      server = Server()
  </code></pre>
  
  <p>Because I couldn't get the bash solution to work I tried <a href="https://stackoverflow.com/questions/4675728/redirect-stdout-to-a-file-in-python">this other solution</a> whether that works for me. It behaves exactly the same like the bash based method. So my service writes nothing to the log file although the empty file is created.</p>