Format: application/x-python-code
1 o
2
3 ��h[ � @ sl d Z ddlZddlZddlZddlZddlmZ dd� Zejfdd�Z dd � Z
4 d
5 d� Zdd
6 � Zddd�Z
7 dS )z�Common utilities for the various process_* implementations.
8
9 This file is only meant to be imported by the platform-specific implementations
10 of subprocess utilities, and it contains tools that are common to all of them.
11 � N)� py3compatc
12 C sH ddl }z| �� W S ty# } z|j |jkr� W Y d}~dS d}~ww )z�Read from a pipe ignoring EINTR errors.
13
14 This is necessary because when reading from pipes with GUI event loops
15 running in the background, often interrupts are raised that stop the
16 command from completing.r N)�errno�read�IOErrorZEINTR)�pr �err� r �Sc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/utils/_process_common.py�read_no_interrupt s
17 ���r
18 c C sp t j�� t j�� t jdk}t| t�}d}|r'tjdkr'dtj v r'tj d }t
19 j| ||t
20 jt
21 j||d�}zSz||�}W n t
22 yU td� t j�� t j�� d}Y nw W |jdu rpz
23 |�� |�� W n tyo Y nw |jdu r�z|�� W |S ty� Y |S w |S |jdu r�z
24 |�� |�� W n ty� Y nw |jdu r�z|�� W w ty� Y w w w )a� Open a command in a shell subprocess and execute a callback.
25
26 This function provides common scaffolding for creating subprocess.Popen()
27 calls. It creates a Popen object and then calls the callback with it.
28
29 Parameters
30 ----------
31 cmd : str or list
32 A command to be executed by the system, using :class:`subprocess.Popen`.
33 If a string is passed, it will be run in the system shell. If a list is
34 passed, it will be used directly as arguments.
35 callback : callable
36 A one-argument function that will be called with the Popen object.
37 stderr : file descriptor number, optional
38 By default this is set to ``subprocess.PIPE``, but you can also pass the
39 value ``subprocess.STDOUT`` to force the subprocess' stderr to go into
40 the same file descriptor as its stdout. This is useful to read stdout
41 and stderr combined in the order they are generated.
42
43 Returns
44 -------
45 The return value of the provided callback is returned.
46 �win32N�posix�SHELL)�shell�
47 executable�stdin�stdout�stderr� close_fdsz^C)�sysr �flushr �platform�
48 isinstance�str�os�name�environ�
49 subprocess�Popen�PIPE�KeyboardInterrupt�print�
50 returncode� terminate�poll�OSError�kill)�cmd�callbackr r r r r �outr r r �process_handler+ sj
51
52
53
54
55 �
56
57 ��
58
59 �
60
61 ��
62 ��
63 ��r) c C s( t | dd� tj�}|du rdS t�|�S )a� Run a command and return its stdout/stderr as a string.
64
65 Parameters
66 ----------
67 cmd : str or list
68 A command to be executed in the system shell.
69
70 Returns
71 -------
72 output : str
73 A string containing the combination of stdout and stderr from the
74 subprocess, in whatever order the subprocess originally wrote to its
75 file descriptors (so the order of the information in this string is the
76 correct order as would be seen if running the command in a terminal).
77 c S s | � � d S )Nr ��communicate�r r r r �<lambda>� � zgetoutput.<locals>.<lambda>N� )r) r �STDOUTr �decode)r&