EOFError when starting with subproccess

EOFError when starting with subproccess



When i start my python3 script with subproccess from an other script i get the following error:


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



But when i start the script normally with python3 generate.py it works totally fine with no error.



script1:


import subprocess
p = subprocess.Popen(["python3", "test2.py"])



script2:


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.")





can you try p = subprocess.call(["python3", generatefile]) ? you should show a Minimal, Complete, and Verifiable example of your script1.
– Jean-François Fabre
Aug 20 at 10:19



p = subprocess.call(["python3", generatefile])





Your second script expects to read from stdin on input("Select the keyword preset you want to use:") But you are not providing any for the invoked subprocess as far as I can see
– FlyingTeller
Aug 20 at 10:23


stdin


input("Select the keyword preset you want to use:")





@Jean-FrançoisFabre python3 pre-generate.py File "generate.py", line 272 ^ SyntaxError: unexpected EOF while parsing
– Thiplol
Aug 20 at 10:27





@FlyingTeller i want the user to type 1 2 3 or 4 in the subproccess
– Thiplol
Aug 20 at 10:29





you probably redirected stdin earlier. Show a Minimal, Complete, and Verifiable example of the first script
– Jean-François Fabre
Aug 20 at 10:32




2 Answers
2



You are using subprocess.Popen which is a by default non blocking, piece of code, hence You program cursor moves rather than waiting for the input from the user. But what you need is a code which is blocking your program cursor. subprocess.call exactly does it. It would be waiting for the other command to execute completely.


subprocess.Popen


subprocess.call



You need to use subprocess.call to solve your problem. Just change your script2 file with this


subprocess.call


import subprocess
p = subprocess.call(["python", "abca.py"])



You can read more about the difference between subprocess.Popen and subprocess.call in this answer. Which describes when to use which command and the difference between them


subprocess.Popen


subprocess.call





my first comment suggested that, and OP commented back that it had the same effect.
– Jean-François Fabre
Aug 20 at 12:25





I could replicate the issue. And when I used subprocess.call it got solved
– argo
Aug 20 at 12:27


subprocess.call





now I'm jealous. it makes sense.
– Jean-François Fabre
Aug 20 at 12:29






Hahaha. Seems like you did the same mistake as I did. You were trying to execute it from IDE. Now while executing it from terminal it got replicated. :P
– argo
Aug 20 at 12:31





Hahaha my mistake was trying to execute it in my head. Actually I thought that there was more than this in op first script. Let's see if you get acceptance.
– Jean-François Fabre
Aug 20 at 12:35




You have to redirect stdin and stdout with the call of script2.py, can use subporcess.PIPE for that:


stdin


stdout


script2.py


p = subprocess.Popen(["python3", "test2.py"], stdin=subprocess.PIPE,
stdout=subprocess.PIPE)






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

How to change the default border color of fbox? [duplicate]

Henj