Find the answer to your Linux question:
Results 1 to 9 of 9
hi all what is the meaning of this. 2> /dev/null can u please explain. thank you in advance...
  1. #1
    Linux Newbie
    Join Date
    Feb 2007
    Location
    hyderabad, india
    Posts
    247

    Redirecting to dev/null

    hi all
    what is the meaning of this.
    2> /dev/null
    can u please explain.

    thank you in advance
    "Relationships are built on trust and communication"

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Have a read of this:

    Code:
    http://www.tldp.org/LDP/Bash-Beginners-Guide/html/sect_08_02.html#sect_08_02_03
    Regards

  3. #3
    Linux Newbie
    Join Date
    Feb 2007
    Location
    hyderabad, india
    Posts
    247

    thank you for quick replay

    Quote Originally Posted by Franklin52 View Post
    Have a read of this:

    Code:
    http://www.tldp.org/LDP/Bash-Beginners-Guide/html/sect_08_02.html#sect_08_02_03
    Regards
    yeah!
    /dev/null -> errors will not print in the terminal and it redirect to null.
    ok
    but, why we use "2>", especially "2".

    and can i use "2> /dev/null" in my program(it is big program).
    is there any effect to my source.(program).

    thank you in advance
    "Relationships are built on trust and communication"

  4. #4
    Linux User
    Join Date
    Oct 2004
    Location
    /dev/random
    Posts
    404
    2 is the stderr file descriptor.
    The Unforgiven
    Registered Linux User #358564

  5. #5
    Linux Newbie
    Join Date
    Feb 2007
    Location
    hyderabad, india
    Posts
    247

    thank you for quick replay

    Quote Originally Posted by the_unforgiven View Post
    2 is the stderr file descriptor.
    can i use this in my program.
    tell me if there is any effects.

    thank you in adavnce
    "Relationships are built on trust and communication"

  6. #6
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    It's mostly used with the system- or popen functions.
    On what case do you want to use that in your C program?

    Regards

  7. #7
    Linux Newbie
    Join Date
    Feb 2007
    Location
    hyderabad, india
    Posts
    247

    thank you for quick replay

    Quote Originally Posted by Franklin52 View Post
    It's mostly used with the system- or popen functions.
    On what case do you want to use that in your C program?

    Regards
    while running my exe(excuted file)
    for ex:
    linux.c is my file and compile like this
    cc linux.c -o linux
    and run it in the terminal
    ./linux 2> /dev/null

    can i do like this

    help me

    thank you in avdvance
    "Relationships are built on trust and communication"

  8. #8
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    That means that an error message from your program, you write with these functions, goes to /dev/null:

    Code:
    perror("Error!");
    fprintf(stderr, "%s: %s\n", "Error: ", "error message");
    Regards

  9. #9
    Linux User
    Join Date
    Oct 2004
    Location
    /dev/random
    Posts
    404
    When a process is started by the kernel, it opens 3 file descriptors by default for every process:
    o. 0 -> stdin (mapped to keyboard)
    o. 1 -> stdout (mapped to the monitor/console/terminal)
    o. 2 -> stderr (mapping same as stdout)

    Conventionally, good programming practice says that all the error messages by any program should be output to stderr (i.e. fd = 2) - that's what the standard functions like perror() do.

    This is because, if you want to capture only the error messages separately, the stderr file descriptor can be redirected to a file while normal output keeps coming to stdout fd - this way you get more control over how to handle the messages.

    If you expect some error messages to be dumped by a program even in normal cases and want to just send them to trash, you use "2> /dev/null" construct.

    HTH
    The Unforgiven
    Registered Linux User #358564

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...