Linux2010.07.07 16:30
글들을 찾아보면
comand > logfile 2>&1
이라고 하면 command를 실행하면서 생기는 출력(stdout)과 에러(stderr)을 logfile로 저장한다고 한다.

하지만, 막상 저장해보면 순서가 뒤죽박죽 되는것으로 보인다.
$ v4l-info /dev/video0 2> v4l.dev0 1>&2
### video4linux device info [/dev/video0] ###
general info
    VIDIOCGCAP
        name                    : "DC10plus[0]"
        type                    : 0x29 [CAPTURE,OVERLAY,CLIPPING]
        channels                : 3
        audios                  : 0
        maxwidth                : 640
        maxheight               : 480
        minwidth                : 48
        minheight ioctl VIDIOCGTUNER: Invalid argument
ioctl VIDIOCGAUDIO: Invalid argument
              : 32

channels
    VIDIOCGCHAN(0)
        channel                 : 0
        name                    : "Composite"
        tuners                  : 0
        flags                   : 0x0 []
        type                    : CAMERA
        norm                    : 1
    VIDIOCGCHAN(1)
        channel                 : 1
        name                    : "S-Video"
        tuners                  : 0
        flags                   : 0x0 []
        type                    : CAMERA
        norm                    : 1
    VIDIOCGCHAN(2)
        channel                 : 2
        name                    : "Internal/comp"
        tuners                  : 0
        flags                   : 0x0 []
        type                    : CAMERA
        norm                    : 1

tuner

audio

picture
    VIDIOCGPICT
        brightness              : 32896
        hue                     : 32896
        colour                  : 33026
        contrast                : 33026
        whiteness               : 0
        depth                   : 16
        palette                 : YUYV

buffer
    VIDIOCGFBUF
        base                    : (nil)
        height                  : 768
        width                   : 1024
        depth                   : 32
        bytesperline            : 4096

window
    VIDIOCGWIN
        x                       : 0
        y                       : 0
        width                   : 0
        height                  : 0
        chromakey               : 0
        flags                   : 0

$ v4l-info /dev/video0
### video4linux device info [/dev/video0] ###
general info
    VIDIOCGCAP
    name                    : "DC10plus[0]"
    type                    : 0x29 [CAPTURE,OVERLAY,CLIPPING]
    channels                : 3
    audios                  : 0
    maxwidth                : 640
    maxheight               : 480
    minwidth                : 48
    minheight               : 32

channels
    VIDIOCGCHAN(0)
    channel                 : 0
    name                    : "Composite"
    tuners                  : 0
    flags                   : 0x0 []
    type                    : CAMERA
    norm                    : 1
    VIDIOCGCHAN(1)
    channel                 : 1
    name                    : "S-Video"
    tuners                  : 0
    flags                   : 0x0 []
    type                    : CAMERA
    norm                    : 1
    VIDIOCGCHAN(2)
    channel                 : 2
    name                    : "Internal/comp"
    tuners                  : 0
    flags                   : 0x0 []
    type                    : CAMERA
    norm                    : 1

tuner
ioctl VIDIOCGTUNER: Invalid argument

audio
ioctl VIDIOCGAUDIO: Invalid argument

picture
    VIDIOCGPICT
    brightness              : 32896
    hue                     : 32896
    colour                  : 33026
    contrast                : 33026
    whiteness               : 0
    depth                   : 16
    palette                 : YUYV

buffer
    VIDIOCGFBUF
    base                    : (nil)
    height                  : 768
    width                   : 1024
    depth                   : 32
    bytesperline            : 4096

window
    VIDIOCGWIN
    x                       : 0
    y                       : 0
    width                   : 0
    height                  : 0
    chromakey               : 0
    flags                   : 0

두가지를 다 리다이렉션은 하지만, 버퍼로 인해서 밀리는건가.. 아니면 다른 명령어가 있는걸까?
신고
Posted by 구차니

댓글을 달아 주세요

Linux2010.02.22 13:21
리다이렉션은, 데이터의 흐름(?)을 다른 곳으로 돌려주는 것을 의미한다.

일반적으로
fd = 0 은 stdin(입력)
fd = 1 은 stdout(표준출력)
fd = 2 는 stderr(표준에러출력)
으로 설정되는데, 이러한 출력을 다른 곳으로 돌려주는 역활을 한다.

예를들어,
에러만 파일에 저장하려면
make 2> err.log

일반메시지만 저장하려면
make > err.log

둘다 저장하려면
make > err.log 2>&1

으로 하면된다.

make 2>&1 err.log
라고 하면 에러가나니, 반드시 파일명과 함께 리다이렉션시킬 방향을 별도로 적어 주어야 한다.


REDIRECTION
       Before  a command is executed, its input and output may be redirected using a special notation interpreted by the
       shell.  Redirection may also be used to open and close files for the current shell  execution  environment.   The
       following  redirection  operators may precede or appear anywhere within a simple command or may follow a command.
       Redirections are processed in the order they appear, from left to right.

       In the following descriptions, if the file descriptor number is omitted, and the first character of the  redirec-
       tion  operator is <, the redirection refers to the standard input (file descriptor 0).  If the first character of
       the redirection operator is >, the redirection refers to the standard output (file descriptor 1).

       The word following the redirection operator in the following descriptions, unless otherwise noted,  is  subjected
       to  brace  expansion,  tilde  expansion,  parameter  expansion, command substitution, arithmetic expansion, quote
       removal, pathname expansion, and word splitting.  If it expands to more than one word, bash reports an error.

       Note that the order of redirections is significant.  For example, the command

              ls > dirlist 2>&1

       directs both standard output and standard error to the file dirlist, while the command

              ls 2>&1 > dirlist

       directs only the standard output to file dirlist, because the standard error was duplicated  as  standard  output
       before the standard output was redirected to dirlist.

[링크 : http://linux.die.net/man/1/bash]


신고

'Linux' 카테고리의 다른 글

diff의 -u 옵션 출력 내용 읽기 how read diff unified format?  (0) 2010.02.23
configure 관련 문서 모음  (0) 2010.02.23
bash 리다이렉션(redirection)  (0) 2010.02.22
리눅스 드라이버 / 모듈  (0) 2010.02.19
bash shell - TMOUT 환경변수  (0) 2010.02.18
chmod(3)  (0) 2010.02.18
Posted by 구차니

댓글을 달아 주세요

Linux2009.06.19 23:12
일반적으로 많이 사용하는 리다이렉션은

>  - 파일에 저장(새로파일 생성)
<  - 파일에서 불러옴
|  - 파이프라인, 결과를 이어줌
>> - 파일에 저장(기존파일에 이어서 붙임)
이정도이고, 잘 사용되지는 않지만 유용한 것으로는

2>  - 에러만 파일에 저장
정도가 있다.
>는 stdout 만 리다이렉션해서 화면으로는 에러가 출력되고
2>는 stderr 만 리다이렉션해서 화면으로는 정상 메시지가 출력된다.

둘다 리다이렉션해서 파일로 저장하고 싶다면

2>&1
이렇게 하면 된다.
예를 들어 컴파일시 모든 메시지를 저장하고 싶다면
$ make install 1> err.log 2>&1
라고 하면 된다.

> word
    The standard output (file descriptor 1) is sent to the file word which is created if it does not already exist.

>> word

    The standard output is sent to file word. If the file exists then output is appended (by seeking to the end); otherwise the file is created.

< word

    The standard input (file descriptor 0) is taken from the file word.

<< word

    The standard input is taken from the lines of shell input that follow up to but not including a line consisting only of word. If word is quoted then no interpretation of the document occurs. If word is not quoted then parameter and command substitution occur and \ is used to quote the characters \ $ ` and the first character of word. In the latter case \newline is ignored (c.f. quoted strings).

>& digit

    The file descriptor digit is duplicated using the system call dup (2) and the result is used as the standard output.

<& digit

    The standard input is duplicated from file descriptor digit.

<&-

    The standard input is closed.

>&-

    The standard output is closed.

[링크 : http://www.partmaps.org/era/unix/shell.html]

<&Digit      Duplicates standard input from the file descriptor specified by the Digit parameter
>& Digit     Duplicates standard output in the file descriptor specified by the Digit parameter
<&-          Closes standard input
>&-          Closes standard output
<&p          Moves input from the co-process to standard input
>&p          Moves output to the co-process to standard output

[링크 : http://www.softpanorama.org/Scripting/Shellorama/input_and_output_redirection.shtml]

신고
Posted by 구차니

댓글을 달아 주세요