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 in Python by Jasmin

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 by Tamanna

Related Questions In Python

0 votes
1 answer

How to fix this? ValueError: invalid literal for int() with base 10 error in Python

The following are totally acceptable in python: passing ...READ MORE

answered Nov 16, 2018 in Python by Nymeria
• 3,500 points
0 votes
1 answer

Error saying "TypeError: descriptor object needs an argument"

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

answered May 28 in Python by Alisha
0 votes
0 answers

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

I get the following error while executing ...READ MORE

6 days ago in Python by Kamal

edited 6 days ago 11 views
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 2 days ago in Python by Vinayak
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
+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
• 66,910 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 in Python by Omkar
• 66,910 points

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.