나누어진 여러개의 바이너리 파일을 파이프로 넘길 때

mandugukbap의 이미지

여러개로 나누어진 바이너리 파일들을 스트림으로 파이프로 넘기려고 합니다. 예를 들어 이렇게 되는겁니다.

find /data/ -name "sliced-data*" -print | xargs zcat | myprogram

여기서 첫번째 파일이 끝나고 두번째 파일로 넘어가는 순간에 myprogram이 invalid input 같은 에러를 냅니다.

바이너리 스트림이 파일과 파일 사이에서 끊기기 때문에 생기는 문제 같은데, 나누어진 저 파일들을 마치 하나의 파일처럼 스트림 하는 방법이 없을까요?

mandugukbap의 이미지

해 보신 분 안 계신가요?

bugiii의 이미지

나눠진건 묶어서 보내고 받는 쪽에서 풀면 될 것 같아요.

tar 잘 활용하면 될 듯... (무책임)

bushi의 이미지

fifo 를 이용하면요 ?

[bushi@rose tmp]$ echo "hello" > h.t
[bushi@rose tmp]$ echo "world" > w.t
[bushi@rose tmp]$ gzip h.t 
[bushi@rose tmp]$ gzip w.t 
[bushi@rose tmp]$ mkfifo fifo
[bushi@rose tmp]$ find -name "*.gz" -exec zcat {} \; > fifo &
[1] 17849
[bushi@rose tmp]$ cat fifo
hello
world
[1]+  Done                    find -name "*.gz" -exec zcat {} \; > fifo
[bushi@rose tmp]$ 

OTL

stypr의 이미지

bash 혹은 작성하신 myprogram 둘 중 하나에 버그가 있는 겁니다. 쉘 커맨드에서의 | 는 제가 알기로는 순수하게 pipe(2) 시스템콜을 통해 구현됩니다. 즉, bash 는 zcat 의 stdout 을 단순 pipe에 써주는 일을 할 뿐입니다.

invalid input 이란 에러가 어디에서 도출되었는지는 모르겠지만 프로그램 둘 중 하나가 pipe(2) 에 의해 만들어진 file descriptor 를 닫지 않았나 먼저 확인해 봐야 할 듯 합니다.

그렇지 않다면 stdin 을 읽기 위해 사용된 libc 혹은 시스템콜 함수나 errno 정보가 필요하겠지요.

바이너리 스트림이 파일과 파일 사이에서 끊기기 때문에 생기는 문제는 아닙니다.

bushi의 이미지

음... 생각해보니 zcat 이 출력할 수 없는 파일이 섞여 있는게 아닌가 싶네요.

OTL

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.