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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With