A
A
Ai Lab2015-10-09 16:01:50
linux
Ai Lab, 2015-10-09 16:01:50

How to properly use FIFO in Linux?

I'm trying to write a python script to control the player (omxplayer), I can't figure out how to properly interact with it using pipe, the point is, there is a script that waits for commands of the form (turn this on, turn off the rest, etc.)
, ideally you need to start the player process and to feed him a tunnel at the entrance, in which to write commands (it responds to commands like pq, etc.). I am trying to use the following example as a basis:
$ mkfifo /tmp/mylog
$ exec 4<>/tmp/mylog
$ myprogram 2>&1 | tee >&4
$ cat /tmp/mylog # on demend
But it doesn't work. I myself am not very friendly with Linux, but I need to do it)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valery Ryaboshapko, 2015-10-09
@valerium

A named pipe (FIFO) is such a virtual file. As with any file, it can be written to and read from. The peculiarity is that one process can either only write or only read.
From the programmer's point of view, it is enough just to open this file for writing and write what you need there. And that's it.
The easiest way to write to a file from a shell is by redirecting the output. That is, to send a q command, you need to do
In Python, you can get by with the built-in open () function, you only need to know the path to the channel that opens the player.
UPD. But most likely, you need ordinary unnamed pipes. To do this, there is a subprocess module that can launch the specified application and pass commands to it on standard input. This is well described in the subprocess documentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question