F
F
fsfsfs322020-09-12 14:53:32
Java
fsfsfs32, 2020-09-12 14:53:32

How to write to the outgoing for the parent (incoming for the child) stream in ProcessBildere in java?

jaba

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class test {
    public static void main(String args[]) throws Exception {
        Process pb = new ProcessBuilder().command("php", "php.php", "123").start();
        BufferedReader in = new BufferedReader(new InputStreamReader(pb.getInputStream()));
        PrintWriter out = new PrintWriter(pb.getOutputStream());

        Thread.sleep(1000);
        out.println("321\r\n\r\n");

        System.out.println(in.readLine());
        System.out.println(in.readLine());
        System.out.println(in.readLine());
        System.out.println(in.readLine());
        System.out.println(in.readLine());

    }
}

----------------
pha
<?

$f = fopen("php://stdin","r+");
$read = fread($f,4096);
$read = str_replace("\r\n","",$read);
fclose($f);

echo "3331\n";
echo $argv[1]."\n";
echo "3332\n";
echo $read."\n";
echo "3333\n";


Output:
null
null
null
null
null
null

Expected output:
3331
123
3332
321
3333

Why does the program output incorrect values?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question