파이프되지 않은 입력에 대해 정상적으로 작동하는 프로그램에서 파이프 입력에서 읽는 것을 중단하면 이상한 오류가 발생합니다 ("존재하지 않는 파이프에 쓰려고했습니다."). 이 오류의 원인을 피하는 방법은 무엇입니까?Java : 파이프를 표준으로 올바르게 처리하기
코드 :
package com.example.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class PipeTest {
static public void main(String[] args) throws IOException
{
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
int i = 0;
while (i < 10)
{
String s = r.readLine();
if (s == null)
break;
++i;
System.out.println(i);
}
}
}
런타임 출력 (testfile.txt는 10 개 이상의 라인 그냥 큰 텍스트 파일입니다) :하지에서
C:\proj\java\test-pipe\bin>java com.example.test.PipeTest < ../testfile.txt
1
2
3
4
5
6
7
8
9
10
C:\proj\java\test-pipe\bin>type ..\testfile.txt | java com.example.test.PipeTest
1
2
3
4
5
6
7
8
9
10
The process tried to write to a nonexistent pipe.
문제는 OS가 파일 경로 구분 기호로 백 슬래시를 사용한다는 것입니다. (더 직접적으로, 당신은 Windows를 사용합니다.) – AJMansfield