Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python read from file desriptor 3

Tags:

python

stderr

I need to read stream from FD 3(STDERR) in Python.

In perl I would do this:

# Open the audio file descriptor
$audio_fh->fdopen( 3, "r" );

$bytes_read = $audio_fh->read($buffer, 80000)

How do I do the same in Python?

like image 473
Ran Avatar asked Jun 12 '26 08:06

Ran


1 Answers

Use os.fdopen to get a file object for a file descriptor.

import os
audio_fh = os.fdopen(3)

buffer = audio_fh.read(80000)

You can also read directly from the file descriptor with

buffer = os.read(3, 80000)
like image 142
chepner Avatar answered Jun 15 '26 04:06

chepner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!