Execute java class in PHP

后端 未结 4 1965
眼角桃花
眼角桃花 2021-01-16 01:50

I want to call a java program and fetch it\'s output in stdout. I followed the suggestions in stackoverflow. But it doesn\'t work.

I have add the class file to my C

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-16 02:32

    try pipe

    $command = 'java Hello';
    $descriptorspec = array(
        1 => array(
            'pipe', 'w'
        )
    );
    $process = proc_open($command, $descriptorspec, $pipes);
    if (!is_resource($process)) {
        exit("failed to create process");
    }
    $content = stream_get_contents($pipes[1]);
    fclose($pipes[1]);
    if (proc_close($process) === 0) {
        print_r($content);
    }else{
        exit("failed to execute Hello");
    }
    

提交回复
热议问题