2

以下を実装するための助けが必要です。次のような C プログラム ファイルがあります。

#include <stdio.h>

main()
{
  int x;
  int args;

  printf("Enter an integer: ");
  if (( args = scanf("%d", &x)) == 0) {
      printf("Error: not an integer\n");
  } else {
      printf("Read in %d\n", x);
  }
  if (( args = scanf("%d", &x)) == 0) {
      printf("Error: not an integer\n");
  } else {
      printf("Read in %d\n", x);
  }
}

a.out を生成しましたが、exec("a.out", $output) を使用してこれを a.out と呼びたいと思います。しかし、私の問題は、要求されたときに整数の値を渡す方法を取得していることです。proc_open() を使ってみましたが、使い方がわかりませんでした。これを処理してこれら 2 つの値を渡し、最終的に受信した結果を出力できる PHP コードを教えていただければ助かります。

よろしくお願いします

4

1 に答える 1

3

私の推測では

$descriptorspec = array(
   0 => array("pipe", "r"),
   1 => array("pipe", "w")
);




$process = proc_open('/full/path/to/a.out', $descriptorspec, $pipes);

if (is_resource($process)) {
    list ($out, $in) = $pipes;

    fwrite($out, "5\n");
    fwrite($out, "7\n");

    echo stream_get_contents($in);
}
于 2012-05-19T16:11:04.887 に答える