Python Forum
Echo call to VLC bash using subprocess.Popen on Linux
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Echo call to VLC bash using subprocess.Popen on Linux
#1
I am using this both on my macosx and linux and it works well.
On linux the shell commands are slightly different:

vlc -I oldrc --rc-unix=/home/user/Documents/Sockets/socket1.sock
vlc -I oldrc --rc-unix=/home/user/Documents/Sockets/socket2.sock

and

echo play | nc -U /home/user/Documents/Sockets/socket1.sock
echo enqueue /home/user/Documents/DualscreenVLC/videos/MVI_2534.MP4 | nc -U /home/user/Documents/Sockets/socket1.sock

I am attempting to use subprocess.Popen in Python for further control but here I run into difficulties on Linux (Ubuntu). It either hangs on the stdout.read() call or when I take this away, all the shell commands are only executed after the script finishes and I get a broken pipe error. The issue seems to be specifically with the 'echo' commands. Did I migrate wrong?
This is the python script:

import subprocess
import time

Socket1Location = "/Users/user/socket1.sock"
Socket2Location = "/Users/user/socket2.sock"
video1 = "/Users/user/Documents/Scripts/DualscreenVLC/videos/video01.mp4"
video2 = "/Users/user/Documents/Scripts/DualscreenVLC/videos/video02.mp4"

def RunVLCCommand1(cmd):
    p = subprocess.Popen("echo " + cmd + " | nc -U " + Socket1Location, shell = True, stdout = subprocess.PIPE)
    errcode = p.wait()
    retval = p.stdout.read()
    print "returning: " + retval
    return retval
    
def RunVLCCommand2(cmd):
    p = subprocess.Popen("echo " + cmd + " | nc -U " + Socket2Location, shell = True, stdout = subprocess.PIPE)
    errcode = p.wait()
    retval = p.stdout.read()
    print "returning: " + retval
    return retval

subprocess.Popen(["/Applications/VLC.app/Contents/MacOS/VLC","--rc-unix=/Users/user/socket1.sock"])
subprocess.Popen(["/Applications/VLC.app/Contents/MacOS/VLC","--rc-unix=/Users/user/socket2.sock"])

#RunVLCCommand1 and 2 can now be used to send commands to VLC, for example RunVLCCommand1('play')
Reply


Messages In This Thread
Echo call to VLC bash using subprocess.Popen on Linux - by LuukS001 - Jan-03-2019, 04:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Understanding subprocess.Popen Pedroski55 6 2,150 May-12-2024, 10:46 AM
Last Post: Pedroski55
  Is possible to run the python command to call python script on linux? cuten222 6 2,472 Jan-30-2024, 09:05 PM
Last Post: DeaD_EyE
Information subprocess.Popen() suddenly giving me grief? davecotter 3 1,863 Dec-13-2023, 10:49 PM
Last Post: davecotter
  I'm trying to make my Alexa/Echo dot 3 powered by ChatGPT.... mariozio 1 1,765 Apr-20-2023, 05:24 PM
Last Post: farshid
  Use subprocess.Popen and time.sleep chucky831 2 3,055 Aug-11-2022, 07:53 PM
Last Post: carecavoador
  Call a bash script from within a Python programme Pedroski55 6 3,702 Dec-06-2021, 01:53 PM
Last Post: DeaD_EyE
  use subprocess on linux\pi wwith a "grep " command korenron 2 11,388 Oct-19-2021, 10:52 AM
Last Post: DeaD_EyE
  continue if 'subprocess.call' failes tester_V 11 9,794 Aug-26-2021, 12:16 AM
Last Post: tester_V
  printing out the contents aftre subprocess.call() Rakshan 3 4,174 Jul-30-2021, 08:27 AM
Last Post: DeaD_EyE
  Subprocess.Popen() not working when reading file path from csv file herwin 13 24,951 May-07-2021, 03:26 PM
Last Post: herwin

Forum Jump:

User Panel Messages

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