Server for Information Technologies ������ ��������������
������� �������������� ����������
(095) 932-9212, 932-9213, 939-0783
E-mail: [email protected]
������ �������� ����(!) ������������� ���������� CIT Forum CD-ROM

POPEN(3S)

��������
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" - ��� �������� ������.

������

  1. �������� �������� ��������� ������:
    	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)].
Comments: [email protected]
Designed by Andrey Novikov
Copyright © CIT