How can I replace socat code with python code

182 Views Asked by At

Right now I'm using subprocess to create communication between two virtual serial ports as such:

  def socat_runner(self):
      self.socat_subprocess = subprocess.Popen(['socat', '-d', '-d', 'pty,raw,echo=0', 'pty,raw,echo=0'],
                                                             stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
      print("subproc id: ", self.socat_subprocess.pid)
      line = self.socat_subprocess.stdout.readline().decode().strip('\n')
      port_location_in_string = line.find('/dev/pts')
      self.port1 = line[port_location_in_string:]
      line = self.socat_subprocess.stdout.readline().decode()
      port_location_in_string = line.find('/dev/pts')
      self.port2 = line[port_location_in_string:]

I'm using both port1 and port2

I would to replace this CMD approach with python approach

0

There are 0 best solutions below