You are not logged in.
I am trying to control two instances of VLC from a python script. To communicate I use unix sockets and netcat.
In the terminal it works well like this:
Initialize both instances:
vlc -I oldrc --rc-unix=/home/user/Documents/Sockets/socket1.sock
vlc -I oldrc --rc-unix=/home/user/Documents/Sockets/socket2.sock
Enqueue and play with:
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
But when I translate it in Python to subprocess.Popen calls the script stops working.
On my mac osx system it does work... is there something wrong with the way I migrated it?
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"
duration = 30
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
print("BEFORE SUBPROCESS 1 : " + RunVLCCommand1("status"))
print("BEFORE SUBPROCESS 2 : " + RunVLCCommand2("status"))
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"])
#wait while initialising
while RunVLCCommand1("status") == "" or RunVLCCommand2("status") == "":
print "Sockets loading..."
time.sleep(1)
if RunVLCCommand1("status") != False and RunVLCCommand2("status") != False:
print "Sockets loaded"
#load videos
RunVLCCommand1("enqueue " + video1)
RunVLCCommand2("enqueue " + video2)
time.sleep(2)
RunVLCCommand1("play")
RunVLCCommand1("pause")
RunVLCCommand2("play")
RunVLCCommand2("pause")
#videos ready, wait for user input
raw_input("Press enter to start video...")
RunVLCCommand1("pause")
RunVLCCommand2("pause")
Offline