如何在PHP中向子进程发送控制信号?

时间:2018-07-15 08:05:15

标签: php bash

我们在Linux终端中通过控制键(CTRL + C,CTRL + D,CTRL + Z等)控制进程。您可以在此处找到其中的一些

https://www.howtogeek.com/howto/ubuntu/keyboard-shortcuts-for-bash-command-shell-for-ubuntu-debian-suse-redhat-linux-etc/

和控制字符: https://en.wikipedia.org/wiki/Control_character

我发现按这些键会向终端发送信号,例如按Ctrl + D发送传输结束字符(EOT),按Ctrl + Z发送替代字符(Ctrl + C发送什么?EOF?)< / p>

我想对php子进程做同样的事情。

我们创建一个流程并通过管道对其进行控制。下面是一个示例:

<?php
$descriptorspec = array(
    0 => array("pipe", "r"),//STDIN we write to it
    1 => array("pipe", "w"),//STDOUT we read output from it
    2 => array("pipe", "w"));//STDERR we read error output from it

$process = proc_open("/bin/bash", $descriptorspec, $pipes);//open the process.I open bash here

$STDINVal="WhatShouldBeSentToProcessToDo(Ctrl+C,Ctrl+D,...)?";//We set input here

fwrite($pipes[0],$STDINVal);//We send input to the process by writing it to STDIN
fclose($pipes[0]);
?>

我的问题是如何向过程发送控制信号? 谢谢。

0 个答案:

没有答案
相关问题