0

I want to send some inputs to a cmd based programme using python. The program takes normally type inputs from keyboard.

I tried as:

P1=subprocess.Popen("my_program",stdin=subprocess.PIPE,stdout=subprocess.PIPE,sterr=subprocess.PIPE)
p1out,p1err=P1.communicate(input="my_input")

But gave error as "it requires byte like object not str". I had also tried with P1.stdin.write() method and gave same error again. What should be my input dtype?

1
  • you may need to pass arg encoding='utf-8' when you call Popen Commented Apr 17, 2019 at 13:15

2 Answers 2

2

It seems like all you have to change is your string to a 'bytes' type.

type("my_input")
>>>> str
type(b'my_input')
>>>> bytes
Sign up to request clarification or add additional context in comments.

Comments

0

I solved using

my_input=my_input.encode("utf-8")

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.