Python Forum
How can I use GNU readline when the value of sys.stdin has been changed?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I use GNU readline when the value of sys.stdin has been changed?
#7
in a recent project i needed to redirect stdout and stderr.  the way i did it was to use os.open() to open a new POSIX file descriptor then use a couple calls to os.dup2() to change descriptors 1 and 2.  i just made sure i did stdout,flush() ahead of this.  maybe you can do this for stdin (0).  be sure you have empty buffers to avoid mixed data.

Type

stdout.flush()
fd = os.open(ln,os.O_APPEND|os.O_CREAT|os.O_WRONLY)
os.dup2(fd,1) if fd != 1 else None
os.dup2(1,2)
"ln" means "log name".  this is opening log files for several cloud programs.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
RE: How can I use GNU readline when the value of sys.stdin has been changed? - by Skaperen - Dec-30-2016, 10:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pyserial Readline() conversion to array bprosman 1 1,987 Apr-11-2023, 12:44 AM
Last Post: deanhystad
  Greek letters with .readline() and tkinter KinkgOfKeks 7 1,832 Mar-24-2023, 05:13 PM
Last Post: deanhystad
Star Pyserial not reading serial.readline fast enough while using AccelStepper on Arduino MartyTinker 4 4,265 Mar-13-2023, 04:02 PM
Last Post: deanhystad
  When is stdin not connected to a tty, but can still be used interactively? stevendaprano 1 1,059 Sep-24-2022, 05:06 PM
Last Post: Gribouillis
  readline.parse_and_bind() does not work in start-up script of Python interpreter zzzhhh 0 1,586 Jan-18-2022, 11:05 AM
Last Post: zzzhhh
  The behavior of tune model has changed Led_Zeppelin 5 4,547 Oct-21-2021, 06:52 PM
Last Post: jefsummers
  STDIN not working H84Gabor 3 3,696 Sep-06-2021, 08:10 AM
Last Post: H84Gabor
  readline inside and outside functions paul18fr 2 2,102 May-20-2021, 01:15 PM
Last Post: csr
  how can a variable change if I haven't changed it? niminim 5 3,163 Apr-07-2021, 06:57 PM
Last Post: niminim
  TypeError: file must have 'read' and 'readline' attributes hobbyist 6 11,162 Jun-12-2020, 05:12 PM
Last Post: DreamingInsanity

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020