1

I've got a working script that is using PySerial to communicate with a modem using AT commands. However, this communication is cluttering my formatted output as all AT commands sent and modem responses are echoed to stdout:

serial.write("ATE1\r")

Result on stdout:

ATE1
OK

I've tried to create my own output class which redirects sys.stdout and sys.stderr to my own descriptors, which works well with all output except for modem comm.

What I want to achieve is that all comm. is performed behind the scene so to speak. Perhaps I'm missing a parameter or something when setting up PySerial? Does anyone know how to suppress this output? Any ideas greatly appreciated!

Thanks /C

Circle
  • 11
  • 1
  • how do you redirect the output, [by replacing sys.stdout,sys.stderr or at C file descriptor level](http://stackoverflow.com/a/22434262/4279)? – jfs Sep 06 '14 at 19:12
  • Within my output class Output (instantiated as "output") I do: `self.stdout = sys.stdout self.stderr = sys.stderr sys.stdout = open(os.devnull, 'w') sys.stderr = open(os.devnull, 'w')`. When I want to print something, I call my defined method "write": `output.write(text)`. – Circle Sep 06 '14 at 19:51
  • then try os.dup2 code from my answer – jfs Sep 06 '14 at 19:53

0 Answers0