|
��������
popen, pclose - �������� � ���������� ������ �����
���������� � ��������
���������
#include <stdio.h> FILE *popen (command, type) char *command, *type; int pclose (stream) FILE *stream;
��������
����������� ������� popen �������� ��������� �� �������
�������� � ����������� ������� ������. ������ �� ���,
command, �������� ������� shell'�, � ������ ������ ����� �����/������: "r" ��� ������ � "w" ��� ������.
������� popen ������� ����� ����� ���������� ����������
� ��������� ��������. ������������ �������� - ��� ��������� �� �����. ���� ����� ����� "w", �� ����� ������
�� ����������� ���� �������, ������ � ��������� �����.
���� ����� ����� "r", �� ����� ������ �� ������������
������ �������, ����� �� ���������� ������.
�����, �������� � ������� popen, ������ ���� ������ � ������� ������� pclose, ������� ������� ���������� ����������� �������� ���������� ������� � ������ ��� ��� ����������.
��������� �������� ����� �����������, ������� � ������� "r" ����� ���� ������������ ��� ������� ������, � ������� � ������� "w" - ��� �������� ������.
������
char *cmd = "ls *.c"; FILE *ptr; if ((ptr = popen (cmd, "r")) != NULL) while (fgets (buf, n, ptr)) != NULL) (void) printf ("%s", buf);
�� ����������� ����� ����� �������� ����� ���� ������ � ����������� .c, ������������� �������� ��������.
��. �����
pipe(2), wait(2), fclose(3S), fopen(3S), stdio(3S),
system(3S).
�����������
������� popen ���������� ������ ��������� (NULL), ����
���� ��� ������� �� ����� ���� �������.
������� pclose ���������� -1, ���� ����� �� ������������ � �������� ����������� popen.
���������������
���� ���������, ����� ���������� ������� � �������, ����������� �� popen, ������������ ������ ��� ������ �
����� �����, �� ������ ��� ���� ������������ �������������� ������/�������, ��� ��� ������ � ������� ������������ ��������������. �������� � �������� �������� ����� ���� ������ ����� ����������� ������������ �������
� ������� ������� fflush [��. fclose(3S)].
|