Error saying "ValueError: Invalid file object: <_io.BufferedReader name=9>"

0 votes

I am trying to get a file name and pass it to a command using popen. Then I want to print the output. This is my code:

filePath = tkinter.filedialog.askopenfilename(filetypes=[("All files", "*.*")])

fileNameStringForm = (basename(filePath ))
fileNameByteForm = fileNameStringForm.encode(encoding='utf-8')

process = subprocess.Popen(['gagner','-arg1'], shell = True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process .communicate(fileNameByteForm )

stdout, stderr = process .communicate()  <<------ERROR POINTS TO THIS LINE

stringOutput = stdout.decode('urf-8')

I am getting the following error:

ValueError: Invalid file object: <_io.BufferedReader name=9>
May 28, 2019 in Python by Jasmin

1 answer to this question.

0 votes

Once you've executed the following command, your subprocess has finished and the pipes have been closed and hence the second call will fail


your subprocess has finished and the pipes have been closed. The second call will then fail as a result.

What you want to do instead is

stdout, stderr = process.communicate(input_data)

This will pipe your input data into the subprocess and read stdout and stderr.

answered May 28, 2019 by Tamanna

Related Questions In Python

+1 vote
6 answers
0 votes
1 answer

Error saying "TypeError: descriptor object needs an argument"

The error is pretty straight forward, toy ...READ MORE

answered May 28, 2019 in Python by Alisha
–1 vote
1 answer

Python error saying "NameError: name 'email' is not defined"

you need to define the variable email READ MORE

answered Nov 29, 2019 in Python by Casper
• 160 points
0 votes
1 answer

Python Error saying "NameError: global name 'true' is not defined"

It's a very small mistake. Change true ...READ MORE

answered Jun 17, 2019 in Python by Vinayak
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,182 views
0 votes
0 answers
+4 votes
6 answers
0 votes
1 answer

Python argparse error "NameError: name 'file' is not defined"

The right datatype for destination in argpasrse module ...READ MORE

answered Nov 28, 2018 in Python by Omkar
• 69,040 points
0 votes
1 answer

How to print a message or the error if a file is not found?

To print the message that file is not ...READ MORE

answered Jan 2, 2019 in Python by Omkar
• 69,040 points