Отправка нажатий клавиш в консольное приложение Linux, выполненное с использованием proc_open в php, не работаетPhp

Кемеровские программисты php общаются здесь
Ответить
Гость
 Отправка нажатий клавиш в консольное приложение Linux, выполненное с использованием proc_open в php, не работает

Сообщение Гость »


Im executing an interactive linux console application using php proc_open(). The application is yewtube (forked from mps-youtube). It allows you to search youtube and play youtube audio from the command line. Here is my code to launch the app:

$descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("pipe", "w") // stderr is a pipe that the child will write to ); $env = null; $options = array(); $process = proc_open($cmd, $descriptorspec, $pipes, null, $env, $options); Here's what the UI looks like. there are two ui modes. The first one is where you can search youtube by entering "/search term" and pressing enter. I have no problem using this mode from php and proc_open() by writing to the input buffer:

fwrite($pipes[0], "/cake\n");
Изображение


I have no problem plaing a song either by writin the song number followed by \n to the input buffer

The second mode is when a song is playing :
Изображение


Here is where I am failing to control the application from php. When run on the console I can control the volume with 0 and 9. I can pause the playback with 'spacebar' etc. No need to press enter.

when I try to send these commands to the application by writing to the input buffer it does not respond (the song keeps playing, the volume is unchanged). I've tried with and without the trailing "\n" character. Does anyone have any suggestions? I'm stumped.

In case anyone is wondering why I'm doing this. I have a headless LAMP raspberry pi web server (Ubuntu 20.04.6) attached to my stereo. Was hoping to play youtube audio on it from my phone. I can do it from my laptop by using ssh and kicking off the yewtube application and using it. I can play/pause songs and change volume etc. I was trying to make a simplified web interface for it, so I could use it more easily and from my phone. It is working now, but once I start a song I can't change the volume or pause/stop the song.


Источник: https://stackoverflow.com/questions/780 ... -not-worki
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»