Add proc_open $pipe inputs on the go dynamically

53
May 26, 2022, at 8:30 PM

I am trying to create a C program compiler + executer using PHP.

My PHP code is

<?php
    $cwd='/path/to/pwd';
    $descriptorspec = array(
    0 => array("pipe", "r"),
    1 => array("pipe", "w"),
    2 => array("file", "/path/to/log/file", "a") );
    $process = proc_open("./a.out", $descriptorspec, $pipes, $cwd);
    fwrite($pipes[0], 123);
    fclose($pipes[0]);
    echo stream_get_contents($pipes[1]);
    fclose($pipes[1]);
 

My C file is

#include <stdio.h>
int main() {
    int a;
    printf("Enter a number");
    scanf("%d", &a);
    printf("The value is: %d", a);
    return 0;
}

Now when I run this, I am getting the output

Enter a numberThe value is: 123

Is there anyway to do it like a terminal execution? So it should wait for the input after showing Enter a number. Then once I enter the number it will execute further and show the output.

It will be like a web site with a terminal.

Will it be possible with proc_open and PHP? Is it possible to achieve by using Web socket in some way?

Please help. Thanks in advance.

READ ALSO
Drupal 8 Entity Query - Condition for an unlimited fields

Drupal 8 Entity Query - Condition for an unlimited fields

With Drupal QueryInterface, it's possible to add a condition on the delta itself by using '%delta' like this :

58
Ho to proper enqueue asset in WP?

Ho to proper enqueue asset in WP?

I have a question and I hope you can help meI am an amateur (quite clear :-) ) trying to enqueue some script

42