【发布时间】:2019-01-26 10:51:05
【问题描述】:
当我从另一个脚本使用 subproccess 启动我的 python3 脚本时,我收到以下错误:
Select the keyword preset you want to use:Traceback (most recent call last):
File "test2.py", line 9, in <module>
keywordselect=input("Select the keyword preset you want to use:")
EOFError
但是当我使用 python3 generate.py 正常启动脚本时,它工作得很好,没有错误。
脚本1:
import subprocess
p = subprocess.Popen(["python3", "test2.py"])
脚本2:
print("Keyword")
print("1. Preset1")
print("2. Preset2")
print("3. Preset3")
print("4. Preset4")
print("You can edit the presets in /presets/keywords/.")
selecting = 1
while selecting == 1:
keywordselect=input("Select the keyword preset you want to use:")
if keywordselect == "1":
print("You selected keyword preset 1.")
selectedkeywordlist = "presets/keywords/preset1.txt"
elif keywordselect == "2":
print("You selected keyword preset 2.")
selectedkeywordlist = "presets/keywords/preset2.txt"
elif keywordselect == "3":
print("You selected keyword preset 3.")
selectedkeywordlist = "presets/keywords/preset3.txt"
elif keywordselect == "4":
print("You selected keyword preset 4.")
selectedkeywordlist = "presets/keywords/preset4.txt"
else:
print("You didn't select a valid option, please try again.")
【问题讨论】:
-
你可以试试
p = subprocess.call(["python3", generatefile])吗?您应该显示您的 script1 的 minimal reproducible example。 -
您的第二个脚本期望从
input("Select the keyword preset you want to use:")上的stdin读取,但据我所知,您没有为调用的子进程提供任何内容 -
@Jean-FrançoisFabre python3 pre-generate.py 文件“generate.py”,第 272 行 ^ 语法错误:解析时出现意外 EOF
-
@FlyingTeller 我希望用户在子进程中输入 1 2 3 或 4
-
您之前可能重定向了标准输入。显示第一个脚本的minimal reproducible example
标签: python python-3.x subprocess eoferror