Jan-06-2019, 11:06 AM
Hmm this also hangs... on most forums I see the issues I am having shouldn't be happening. And I had no problems making it work on my MacOSX, could it help to install another OS? Linux Mint for example?
Output:echo play | nc -U <socket location>
import subprocess import socket import select esock, echildsock = socket.socketpair() osock, ochildsock = socket.socketpair() p = subprocess.Popen('vlc -I oldrc --rc-unix=/home/user/Documents/Sockets/socket1.sock', shell = True, stderr = echildsock.fileno(), stdout = ochildsock.fileno()) while p.poll() is None: r, w, x = select.select([esock, osock],[],[], 1.0) if not r: continue # timed out for s in r: print('stdout first echo call ready' if s is osock else 'stderr ready') data = s.recv(1024) print('received', data.decode('utf8')) breakWhen I run exactly the same command from Python but with: echo enqueue /home/user/Documents/DualscreenVLC/videos/video01.mp4
Quote:this hangs both when executed from Python and from the terminal.This seems to indicate that the issue has nothing to do with python. It could be a linux specific issue concerning permissions or the correct use of the commands that you call. The best thing to do is to try to do this completely outside of python by using only commands written in a terminal. Otherwise, the python part of it is only obfuscating the issue. Once you can do it without python, you can implement it with the subprocess module.
#!/usr/bin/python2.7 import subprocess import time import signal import shlex import socket import select esock, echildsock = socket.socketpair() osock, ochildsock = socket.socketpair() omp_cmd = 'vlc -I oldrc --rc-unix=/home/user/Documents/Sockets/socket1.sock' omp_cmd2 ='echo enqueue /home/user/Documents/DualscreenVLC/videos/video01.mp4 | nc -U /home/user/Documents/Sockets/socket1.sock' omp_cmd3 ='echo play | nc -U /home/user/Documents/Sockets/socket1.sock' p = subprocess.Popen(shlex.split(omp_cmd), stderr=echildsock.fileno(), stdout=ochildsock.fileno()) while p.poll() is None: r, w, x = select.select([esock, osock],[],[], 1.0) if not r: continue # timed out for s in r: print('stdout ready' if s is osock else 'stderr ready') data = s.recv(1024) print('received', data.decode('utf8')) break time.sleep(2) p = subprocess.Popen('echo enqueue /home/user/Documents/DualscreenVLC/videos/video01.mp4 | nc -U /home/user/Documents/Sockets/socket1.sock', shell = True, stderr = echildsock.fileno(), stdout = ochildsock.fileno()) while p.poll() is None: r, w, x = select.select([esock, osock],[],[], 1.0) if not r: continue # timed out for s in r: print('stdout first echo call ready' if s is osock else 'stderr ready') data = s.recv(1024) print('received', data.decode('utf8')) break time.sleep(2) raw_input("Press enter to start video...") omp_cmd='echo play | nc -U /home/user/Documents/Sockets/socket1.sock' p1 = subprocess.Popen(shlex.split(omp_cmd), stderr=echildsock.fileno(), stdout=ochildsock.fileno()) while p1.poll() is None: r, w, x = select.select([esock, osock],[],[], 1.0) if not r: continue # timed out for s in r: print('stdout ready' if s is osock else 'stderr ready') data = s.recv(1024) print('received', data.decode('utf8')) break time.sleep(10) osock.shutdown(socket.SHUT_RDWR) osock.close() esock.shutdown(socket.SHUT_RDWR) esock.close()
p=subprocess.run('vlc -I rc --rc-host localhost:11337 video01.mp4 -d &',shell=True) p=subprocess.run('vlc -I rc --rc-host localhost:11338 video02.mp4 -d &',shell=True) time.sleep(10) p=subprocess.run('echo pause | netcat -q 0 localhost 11337 &', shell=True) p=subprocess.run('echo pause | netcat -q 0 localhost 11338 &', shell=True) time.sleep(2) p=subprocess.run('echo seek 1 | netcat -q 0 localhost 11337 &', shell=True) p=subprocess.run('echo seek 1 | netcat -q 0 localhost 11338 &', shell=True) time.sleep(2) p=subprocess.run('echo pause | netcat -q 0 localhost 11337 &', shell=True) p=subprocess.run('echo pause | netcat -q 0 localhost 11338 &', shell=True)