Linux: cat to named pipe in a python script -


i have java program uses video framegrabber card. program launched through python launcher.py.

the easiest way read video stream found, make java read on named pipe, , works perfectly. session like:

$ mkfifo videopipe $ cat /dev/video1>videopipe 

and in second terminal (since cat command blocking):

$ python launcher.py 

i automate process. unfortunately, result same: java application starts (confirmed through print statement in java program), terminal stalls , nothing appears, exception or else.

since process works manually, guess doing wrong in python program. simplify things, isolated piping part:

from subprocess import call, popen, pipe, check_call  bash_switchto_wintv = ['v4l2-ctl', '-d /dev/video1', '-i 2', '--set-standard=4'] bash_create_fifo_pipe = ['mkfifo', 'videopipe'] bash_pipe_video = 'cat /dev/video1>videopipe'  def run():     try:         print('running bash commands...')         call(bash_switchto_wintv)         call(bash_create_fifo_pipe)         popen(['cat', '/dev/video1'], stdout=open('videopipe', 'w'))     except:         raise runtimeerror('an error occured while piping video')  if __name__ == '__main__':     run() 

which when run, outputs:

running bash commands...      failed open  /dev/video1: no such file or directory 

a little appreciated :-)

if you're using shell=true, pass string:

bash_pipe_video = 'cat /dev/video1 > videopipe' 

currently, cat passed shell script, , /dev/video>videopipe passed shell literal argument -- not parsed part of script text @ all, , having no effect since script (just calling cat) doesn't @ arguments.


alternately, avoid needless shell use (and shell-related bugs such shellshock, , potential injection attacks if accepting argument non-hardcoded source):

popen(['cat', '/dev/video1'], stdout=open('videopipe, 'w')) 

on note unrelated "cat named pipe" question -- sure spaces correct.

bash_switchto_wintv = ['v4l2-ctl', '-d /dev/video1', ...] 

...uses name <space>/dev/video1, with leading space, input device; it's same running v4l2-ctl "-d /dev/video1" in shell, cause same problem.

be sure split arguments correctly:

bash_switchto_wintv = ['v4l2-ctl', '-d', '/dev/video1', ...] 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -