Python Forum
moving from os to subprocess
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
moving from os to subprocess
#1
I am working on a Linux Mint 18.2 laptop.
I used python 2.7 in the past but moved to 3.5 and now 3.6. I have carried on using os.system calls as I cannot figure out the correct syntax for using subprocess calls.
Here is an example of what I am struggling with.
with os.system I can do
vid = home + "/myvids/videos/" + vidstore[thevid]
vid2play = "mpv --fs  " + vid
os.system(vid2play)
 i get the variable home from
from os.path import expanduser
home = expanduser(~)
I have no idea what can replace expanduser and try as I might I cannot find any combination of " ' , and so on which can be passed to subprocess.call which it accepts. I have googled until my eyes swap places but all the suggestions I have tried so far have failed me.
something like this example is fine
import subprocess
subprocess.call(["ls", "-l"])
but how can I use variables as in the os.system call?
I tried 
subprocess.call('mpv', '--fs', vid)
also
subprocess.call('mpv', '--fs', 'vid')
along with various other combinations but get
Quote:Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.6/tkinter/__init__.py", line 1702, in __call__
    return self.func(*args)
  File "./sign-songsPCC.py", line 143, in play_song
    subprocess.call('mpv', '--fs', 'vid') #,  'mwbv_BSL_201712_05_r720P.mp4')
  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

So I do hope someone can point me in the right direction please.
Reply


Messages In This Thread
moving from os to subprocess - by Barrowman - Dec-17-2017, 04:11 PM
RE: moving from os to subprocess - by wavic - Dec-17-2017, 05:59 PM
RE: moving from os to subprocess - by Barrowman - Dec-17-2017, 06:19 PM
RE: moving from os to subprocess - by Barrowman - Dec-17-2017, 07:59 PM
RE: moving from os to subprocess - by wavic - Dec-17-2017, 10:35 PM
RE: moving from os to subprocess - by Barrowman - Dec-17-2017, 11:02 PM
RE: moving from os to subprocess - by wavic - Dec-17-2017, 11:28 PM
RE: moving from os to subprocess - by Barrowman - Dec-18-2017, 09:04 AM
RE: moving from os to subprocess - by wavic - Dec-19-2017, 10:20 PM
RE: moving from os to subprocess - by ezdev - Dec-20-2017, 01:02 AM
RE: moving from os to subprocess - by Barrowman - Dec-20-2017, 09:08 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020