使用pythonfcntl.ioctl公司码头工人22号

2024-05-16 02:50:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用python2在最新的Docker Ubuntu图片中运行了以下代码:

码头工人:

docker pull ubuntu
docker run -it ubuntu /bin/bash

码头工人:

apt update
apt install python
touch test
python

在python中:

>>> import struct
>>> import fcntl
>>> f = open("test", "rb")
>>> binary_data = fcntl.ioctl(f, 2, struct.pack('I', 0))

错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 22] Invalid argument

同样的流程,我在我的电脑和结果,我没有得到任何错误。 我怀疑文件描述符有问题。在这两种情况下,当我调用f.fileno()时,我得到了结果3。在这两种情况下,我都在python2.7.16上运行它

但当我在码头跑的时候:

>>> import struct
>>> import fcntl
>>> f = open("test", "rb")
>>> binary_data = fcntl.ioctl(2, 2, struct.pack('I', 0))

我没有错。你知道吗


Tags: dockertestimportdataubuntu错误aptopen