Bonjour,

j'essaie de transmettre des flux entre des processus (trois Runtime.exec()). La première transmission se passe bien, mais la seconde me produit l'exception "Broken pipe". Qu'est-ce qui peut être la cause de cette exception ? Ci-dessous mon code.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 
Process awk1, sort, awk2;
try {
    awk1 = Runtime.getRuntime().exec(new String[]{"awk", "{print $1,$3,$2}", file1});
    sort = Runtime.getRuntime().exec(new String[]{"sort", "-n", "-k", "1", "-k", "2"});
    awk2 = Runtime.getRuntime().exec(new String[]{"awk", "{print $3}", ">", file2});
 
    new Thread(){
	public void run(){
	    InputStream awk1Input = awk1.getErrorStream();
	    try {
		int c;
		while ((c = awk1Input.read()) != -1) System.out.print((char) c);
		awk1Input.close();
	    } catch (IOException e) {
		e.printStackTrace();
	    }
	}
    }.start();
 
    new Thread(){
	public void run(){
	    InputStream awk1Input = awk1.getInputStream();
	    OutputStream sortOutput = sort.getOutputStream();
	    try {
		int c;
		while ((c = awk1Input.read()) != -1) sortOutput.write((char) c);
		sortOutput.close();
		awk1Input.close();
	    } catch (IOException e) {
		e.printStackTrace();
	    }
	}
    }.start();
 
    new Thread(){
	public void run(){
	    InputStream sortInput = sort.getErrorStream();
	    try {
		int c;
		while ((c = sortInput.read()) != -1) System.out.print((char) c);
		sortInput.close();
	    } catch (IOException e) {
		e.printStackTrace();
	    }
	}
    }.start();
 
    new Thread(){
	public void run(){
	    InputStream sortInput = sort.getInputStream();
	    OutputStream awk2Output = awk2.getOutputStream();
	    System.out.println("lala");
	    try {
		int c;
		while ((c = sortInput.read()) != -1){
		    awk2Output.write((char) c);
		}
		System.out.println("lala");
		sortInput.close();
		awk2Output.close();
	    } catch (IOException e) {
		e.printStackTrace();
	    }
	}
    }.start();
 
} catch (IOException e) {
    e.printStackTrace();
}
Le premier "lala" s'affiche mais pas le second. Et voici l'exception :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
java.io.IOException: Broken pipe
	at java.io.FileOutputStream.writeBytes(Native Method)
	at java.io.FileOutputStream.write(FileOutputStream.java:260)
	at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
	at java.io.BufferedOutputStream.write(BufferedOutputStream.java:78)