PyDev/Python3.1子进程错误没有声明编码

2024-09-19 23:29:59 发布

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

当我跑步时父级.py调用子进程子级.exe出现以下错误

  File "child.exe", line 1
SyntaxError: Non-UTF-8 code starting with '\x90' in file child.exe on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

如果我运行父级.py用儿童.py执行成功地从Eclipse返回“Hello from parent.”。在

如果我跑了父级.py在这两种情况下,从已装运的闲置状态中,不会返回任何内容子级.exe以及儿童.py

我已经阅读了http://python.org/dev/peps/pep-0263/文档并理解了它,可能是误解了它意味着我应该添加我尝试添加的建议注释子级.exe... 他们没有工作。

父级.py

^{pr2}$



子级.exe(用cx冷冻)

import os, sys


if sys.platform == "win32":
    import msvcrt

# Get file descriptor from argument
pipearg = int(sys.argv[1])
if sys.platform == "win32":
    pipeoutfd = msvcrt.open_osfhandle(pipearg, 0)
else:
    pipeoutfd = pipearg

# Read from pipe
# Note:  Could be done with os.read/os.close directly, instead of os.fdopen
pipeout = os.fdopen(pipeoutfd, 'r')
print(pipeout.read())
pipeout.close()

Tags: frompychildhttposwithsysline
1条回答
网友
1楼 · 发布于 2024-09-19 23:29:59
subprocess.Popen(['python', 'child.exe', pipearg], ...

问题是您试图让python读取二进制文件,如果子级.exe是一个普通的windows可执行文件。因为标准的utf8文件不能读取标准的二进制文件。在

也许你想要的只是执行子级.exe只需删除其中的python行:

^{pr2}$

相关问题 更多 >