Mini Shell
�
�[�i � �P � d dl mZ d dl mZ d dl mZ d dlZd dlZd� Zdd�Zdd�ZdS ) � )�print_function)�division)�absolute_importNc � � t | t � � r.| � � � dk rg S t j | � � S t | t
� � r| S g S )z;
Parses a command string into a list of arguments.
� )�
isinstance�str�strip�shlex�split�list)�commands �exec_command.py�
parse_commandr sZ � � �'�3��� ��=�=�?�?�b� � ��I��{�7�#�#�#� �G�T� "� "� ���� � c � � g } t | � � }|st d| � �� � �t j |t j |d�� � } |j � � � }|sn@|� � � dk r'|� |� � � � � �\n4# t $ r'}t dt |� � � � Y d}~nd}~ww xY w|S )z
Execute command
�#The provided command is not valid: T��stdout�env�text� r zCall process error:N)r �
ValueError�
subprocess�Popen�PIPEr �readliner
�append� Exception�printr )r r �result�args�p�output�insts r �exec_commandr&