Contents of question

When I was studying python, I found the following code.

sh.run ('sudo dd if =/proc/net/tcpprobe of = "./ {}/{}-tmp.log" 2>/dev/null&'.format (dest, outprefix), shell = True)

I'm not sure if I look up the "2>/dev/null" part of this code, so please tell me the meaning.

Also. Here's how to get to the GitHub page where the code is shown.

We would like to thank all the experts for their help. Thank you.

  • Answer # 1

    The sh.run () function is a function for executing commands in the shell of the system (OS) on which python is running.
    Since the command string given to the shell is given as an argument, the content of the question is not python, but in this case it is a command of a shell such as Linux.

    2>/dev/nullIs a redirect, which is a way to change the output of a command from the normal output destination.
    here,2Shows the second output, the standard error output (stderr).1Is the standard output (stdout).
    The output destination is/ dev/nullThe file is specified. This file is a special file in which everything you write is discarded.

    So2>/dev/nullMeans that it is an instruction to discard all the errors of the executed command.

  • Answer # 2

    sh.run is a function that is executed in the shell, so if you look in the shell direction, you will find it.

    Save the output to standard output (stdout) and standard error (stderr) to a file |

    And/dev/null is a path that does nothing even if it is output there.