private static PdfPCell PhraseCell(Phrase phrase, int align)
{
PdfPCell cell = new PdfPCell(phrase);
cell.BorderColor = BaseColor.WHITE;
// cell.VerticalAlignment = PdfCell.ALIGN_TOP;
//cell.VerticalAlignment = align;
cell.HorizontalAlignment = align;
cell.PaddingBottom = 2f;
cell.PaddingTop = 0f;
return cell;
}
Файловый дескриптор 1 является стандартным выходом ( stdout
).
Файловый дескриптор 2 является стандартной ошибкой ( stderr
).
Вот один из способов запомнить эту конструкцию (хотя она не совсем точна): сначала 2> 1
может выглядит как хороший способ перенаправить stderr
на stdout
. Однако на самом деле это будет интерпретироваться как «перенаправление stderr
в файл с именем 1
». &
указывает, что ниже приводится дескриптор файла, а не имя файла. Таким образом, конструкция становится: 2> & 1
.
Чтобы ответить на ваш вопрос: он принимает любой вывод ошибок (обычно отправляется в stderr) и записывает его в стандартный вывод (stdout).
Это полезно, например, для «more», когда вам требуется подкачка для всего вывода. Некоторым программам нравится печатать информацию об использовании в stderr.
Чтобы помочь вам запомнить
"2> & 1 "просто указывает все, что отправлено в stderr, вместо этого на stdout.
Я также рекомендую прочитать этот пост о перенаправлении ошибок , где эта тема рассматривается полностью.
That construct sends the standard error stream (stderr
) to the current location of standard output (stdout
) - this currency issue appears to have been neglected by the other answers.
You can redirect any output handle to another by using this method but it's most often used to channel stdout
and stderr
streams into a single stream for processing.
Some examples are:
# Look for ERROR string in both stdout and stderr.
foo 2>&1 | grep ERROR
# Run the less pager without stderr screwing up the output.
foo 2>&1 | less
# Send stdout/err to file (with append) and terminal.
foo 2>&1 |tee /dev/tty >>outfile
# Send stderr to normal location and stdout to file.
foo >outfile1 2>&1 >outfile2
Note that that last one will not direct stderr
to outfile2
- it redirects it to what stdout
was when the argument was encountered (outfile1
) and then redirects stdout
to outfile2
.
This allows some pretty sophisticated trickery.
echo test > afile.txt
redirects stdout to afile.txt
. This is the same as doing
echo test 1> afile.txt
To redirect stderr, you do:
echo test 2> afile.txt
>&
is the syntax to redirect a stream to another file descriptor - 0 is stdin, 1 is stdout, and 2 is stderr.
You can redirect stdout to stderr by doing:
echo test 1>&2 # or echo test >&2
Or vice versa:
echo test 2>&1
So, in short... 2>
redirects stderr to an (unspecified) file, appending &1
redirects stderr to stdout.
Номера относятся к дескрипторам файлов (fd).
stdin
stdout
stderr
2> & 1
перенаправляет fd 2 на 1.
Это работает для любого числа дескрипторов файлов, если программа использует их.
Вы можете посмотреть /usr/include/unistd.h
, если вы их забудете:
/* Standard file descriptors. */
#define STDIN_FILENO 0 /* Standard input. */
#define STDOUT_FILENO 1 /* Standard output. */
#define STDERR_FILENO 2 /* Standard error output. */
Тем не менее, я написал инструменты C, которые используют нестандартные файловые дескрипторы для пользовательского ведения журнала, поэтому вы не увидите его, если не перенаправите его в файл или что-то еще.