2009-05-08 23 views

答えて

3

あなたのプロセスと通信できるようにするproc_open()を使用する必要があります。ここでは

は、私が持っているしたいものの一例です。あなたの例は次のようになります:

// How to connect to the process 
$descriptorspec = array(
    0 => array("pipe", "r"), 
    1 => array("pipe", "w") 
); 

// Create connection 
$process = proc_open("RUNMYSCRIPT.sh", $descriptorspec, $pipes); 
if (!is_resource($process)) { 
    die ('Could not execute RUNMYSCRIPT'); 
} 

// Sleep & send something to it: 
sleep(10); 
fwrite($pipes[0], 'q'); 

// You can read the output through the handle $pipes[1]. 
// Reading 1 byte looks like this: 
$result = fread($pipes[1], 1); 

// Close the connection to the process 
// This most likely causes the process to stop, depending on its signal handlers 
proc_close($process); 
0

単純にキーイベントをそのような外部アプリケーションに送信することはできません。 system()の代わりにproc_open()を使用して外部シェルスクリプトの標準入力に書き込むことは可能ですが、ほとんどのシェルスクリプトはstdinを見るのではなくキーストロークを直接待ち受けます。

代わりに使用する信号があります。事実上、すべてのシェルアプリケーションはSIGTERMやSIGHUPのようなシグナルに応答します。シェルスクリプトを使用してこれらのシグナルをトラップして処理することも可能です。 proc_open()を使用してシェルスクリプトを起動する場合は、proc_terminate()を使用してSIGTERM信号を送信できます。

関連する問題