Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: bufsize must be an integer?

I am making a small program where I can open a file from any part of the computer with it's default editor. This is my code:

from os import *
import subprocess
print("Welcome to my File Finder. Here you can search for a file and open it.")
file_name = str(input("Your file's name:"))
print(subprocess.call(["xdg-open"], file_name))]

But instead of opening, it return this error:

Traceback (most recent call last):
File "Important_tester_projects.py", line 6, in <module>
  print(subprocess.call(["xdg-open"], file_name))
File "/usr/lib/python3.6/subprocess.py", line 267, in call
  with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.6/subprocess.py", line 609, in __init__
  raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer

I have googled to find a solution for this error, but I can't find any that seems to solve my Problem. How can fix my error?

NOTE: My Linux OS uses XFCE, not Gnome.

like image 905
Mahir Islam Avatar asked Feb 25 '26 23:02

Mahir Islam


1 Answers

Instead, use subprocess.check_output(). Since your command has multiple words, parse your command with split() method from shlex lib. Something like this:

import subprocess
import shlex

cmd=shlex.split('[find][2] root_dir -name file_name')
print subprocess.check_output(cmd)
like image 52
Ashot Terteryan Avatar answered Feb 27 '26 13:02

Ashot Terteryan