Python sys.stdin() Examples

The following are 30 code examples for showing how to use sys.stdin(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module sys , or try the search function .

Example 1
Project: kaldi-python-io   Author: funcwj   File: inst.py    License: Apache License 2.0 7 votes vote down vote up
def _fopen(fname, mode):
    """
    Extend file open function, to support 
        1) "-", which means stdin/stdout
        2) "$cmd |" which means pipe.stdout
    """
    if mode not in ["w", "r", "wb", "rb"]:
        raise ValueError("Unknown open mode: {mode}".format(mode=mode))
    if not fname:
        return None
    fname = fname.rstrip()
    if fname == "-":
        if mode in ["w", "wb"]:
            return sys.stdout.buffer if mode == "wb" else sys.stdout
        else:
            return sys.stdin.buffer if mode == "rb" else sys.stdin
    elif fname[-1] == "|":
        pin = pipe_fopen(fname[:-1], mode, background=(mode == "rb"))
        return pin if mode == "rb" else TextIOWrapper(pin)
    else:
        if mode in ["r", "rb"] and not os.path.exists(fname):
            raise FileNotFoundError(
                "Could not find common file: {}".format(fname))
        return open(fname, mode) 
Example 2
Project: supervisor-logging   Author: infoxchange   File: __init__.py    License: Apache License 2.0 6 votes vote down vote up
def supervisor_events(stdin, stdout):
    """
    An event stream from Supervisor.
    """

    while True:
        stdout.write('READY\n')
        stdout.flush()

        line = stdin.readline()
        headers = get_headers(line)

        payload = stdin.read(int(headers['len']))
        event_headers, event_data = eventdata(payload)

        yield event_headers, event_data

        stdout.write('RESULT 2\nOK')
        stdout.flush() 
Example 3
Project: aegea   Author: kislyuk   File: batch.py    License: Apache License 2.0 6 votes vote down vote up
def add_command_args(parser):
    group = parser.add_mutually_exclusive_group()
    group.add_argument("--watch", action="store_true", help="Monitor submitted job, stream log until job completes")
    group.add_argument("--wait", action="store_true",
                       help="Block on job. Exit with code 0 if job succeeded, 1 if failed")
    group = parser.add_mutually_exclusive_group()
    group.add_argument("--command", nargs="+", help="Run these commands as the job (using " + BOLD("bash -c") + ")")
    group.add_argument("--execute", type=argparse.FileType("rb"), metavar="EXECUTABLE",
                       help="Read this executable file and run it as the job")
    group.add_argument("--wdl", type=argparse.FileType("rb"), metavar="WDL_WORKFLOW",
                       help="Read this WDL workflow file and run it as the job")
    parser.add_argument("--wdl-input", type=argparse.FileType("r"), metavar="WDL_INPUT_JSON", default=sys.stdin,
                        help="With --wdl, use this JSON file as the WDL job input (default: stdin)")
    parser.add_argument("--environment", nargs="+", metavar="NAME=VALUE",
                        type=lambda x: dict(zip(["name", "value"], x.split("=", 1))), default=[])
    parser.add_argument("--staging-s3-bucket", help=argparse.SUPPRESS) 
Example 4
Project: iSDX   Author: sdn-ixp   File: client.py    License: Apache License 2.0 6 votes vote down vote up
def _sender(conn,stdin):
    # Warning: when the parent dies we are seeing continual
    # newlines, so we only access so many before stopping
    counter = 0

    while True:
        try:
            line = stdin.readline().strip()

            if line == "":
                counter += 1
                if counter > 100:
                    break
                continue
            counter = 0

            conn.send(line)

            sendLogger.debug(line)

        except:
            pass 
Example 5
Project: Turku-neural-parser-pipeline   Author: TurkuNLP   File: build_lemma_cache.py    License: Apache License 2.0 6 votes vote down vote up
def build(args):
    words={}

    for line in sys.stdin:
        line=line.strip()
        if not line or line.startswith("#"):
            continue
        cols=line.split("\t")
        word=(cols[FORM], cols[UPOS], cols[XPOS], cols[FEATS], cols[LEMMA])
        if word not in words:
            words[word]=0
        words[word]+=1

    for word, count in sorted(words.items(), key=lambda x: x[1], reverse=True):

        if count>args.cutoff:
            w="\t".join(word)
            if len(w.strip().split("\t"))!=5: # make sure there is no empty columns
                print("Skipping weird line", w, file=sys.stderr)
                continue
            print(w)
        else:
            break 
Example 6
Project: knob   Author: francozappa   File: cmds.py    License: MIT License 6 votes vote down vote up
def hciCallback(self, record):
                hcipkt, orig_len, inc_len, flags, drops, recvtime = record

                dummy = "\x00\x00\x00"      # TODO: Figure out purpose of these fields
                direction = p8(flags & 0x01)
                packet = dummy + direction + hcipkt.getRaw()
                length = len(packet)
                ts_sec =  recvtime.second #+ timestamp.minute*60 + timestamp.hour*60*60 #FIXME timestamp not set
                ts_usec = recvtime.microsecond
                pcap_packet = struct.pack('@ I I I I', ts_sec, ts_usec, length, length) + packet
                try:
                    self.wireshark_process.stdin.write(pcap_packet)
                    self.wireshark_process.stdin.flush()
                    log.debug("HciMonitorController._callback: done")
                except IOError as e:
                    log.warn("HciMonitorController._callback: broken pipe. terminate.")
                    self.killMonitor() 
Example 7
Project: knob   Author: francozappa   File: cmds.py    License: MIT License 6 votes vote down vote up
def lmpCallback(self, lmp_packet, sendByOwnDevice, src, dest, timestamp):
                eth_header = dest + src + "\xff\xf0"
                meta_data  = "\x00"*6 if sendByOwnDevice else "\x01\x00\x00\x00\x00\x00"
                packet_header = "\x19\x00\x00" + p8(len(lmp_packet)<<3 | 7)

                packet = eth_header + meta_data + packet_header + lmp_packet
                packet += "\x00\x00" # CRC
                length = len(packet)
                ts_sec =  timestamp.second + timestamp.minute*60 + timestamp.hour*60*60
                ts_usec = timestamp.microsecond
                pcap_packet = struct.pack('@ I I I I', ts_sec, ts_usec, length, length) + packet
                try:
                    self.wireshark_process.stdin.write(pcap_packet)
                    self.wireshark_process.stdin.flush()
                    log.debug("LmpMonitorController._callback: done")
                except IOError as e:
                    log.warn("LmpMonitorController._callback: broken pipe. terminate.")
                    self.killMonitor() 
Example 8
Project: InsightAgent   Author: insightfinder   File: insightfinder.py    License: Apache License 2.0 6 votes vote down vote up
def main():
    # Initialize the logger
    logging.basicConfig()

    # Intialize from our arguments
    insightfinder = InsightfinderStore(*sys.argv[1:])

    current_chunk = 0

    # Get all the inputs
    for line in sys.stdin:
        if insightfinder.filter_string not in line:
            continue
        map_size = len(bytearray(json.dumps(insightfinder.metrics_map)))
        if map_size >= insightfinder.flush_kb * 1000:
            insightfinder.logger.debug("Flushing chunk number: " + str(current_chunk))
            insightfinder.send_metrics()
            current_chunk += 1
        insightfinder.append(line.strip())
    insightfinder.logger.debug("Flushing chunk number: " + str(current_chunk))
    insightfinder.send_metrics()
    insightfinder.save_grouping()
    insightfinder.logger.debug("Finished sending all chunks to InsightFinder") 
Example 9
Project: SublimeKSP   Author: nojanath   File: ksp_compiler.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __call__(self, string):
            # the special argument "-" means sys.std{in,out}
            if string == '-':
                if 'r' in self._mode:
                    return sys.stdin
                elif 'w' in self._mode:
                    return sys.stdout
                else:
                    msg = _('argument "-" with mode %r') % self._mode
                    raise ValueError(msg)

            # all other arguments are used as file names
            try:
                return open(string, self._mode, self._bufsize, self._encoding, self._errors)
            except OSError as e:
                message = _("can't open '%s': %s")
                raise ArgumentTypeError(message % (string, e)) 
Example 10
Project: udapi-python   Author: udapi   File: files.py    License: GNU General Public License v3.0 6 votes vote down vote up
def _token_to_filenames(token):
        if token[0] == '!':
            pattern = token[1:]
            filenames = glob.glob(pattern)
            if not filenames:
                raise RuntimeError('No filenames matched "%s" pattern' % pattern)
        elif token[0] == '@':
            filelist_name = sys.stdin if token == '@-' else token[1:]
            with open(filelist_name) as filelist:
                filenames = [line.rstrip('\n') for line in filelist]
            directory = os.path.dirname(token[1:])
            if directory != '.':
                filenames = [f if f[0] != '/' else directory + '/' + f for f in filenames]
        else:
            filenames = [token]
        return filenames 
Example 11
Project: udapi-python   Author: udapi   File: files.py    License: GNU General Public License v3.0 6 votes vote down vote up
def next_filehandle(self):
        """Go to the next file and retrun its filehandle or None (meaning no more files)."""
        filename = self.next_filename()
        if filename is None:
            fhandle = None
        elif filename == '-':
            fhandle = io.TextIOWrapper(sys.stdin.buffer, encoding=self.encoding)
        elif filename == '<filehandle_input>':
            fhandle = self.filehandle
        else:
            filename_extension = filename.split('.')[-1]
            if filename_extension == 'gz':
                myopen = gzip.open
            elif filename_extension == 'xz':
                myopen = lzma.open
            elif filename_extension == 'bz2':
                myopen = bz2.open
            else:
                myopen = open
            fhandle = myopen(filename, 'rt', encoding=self.encoding)
        self.filehandle = fhandle
        return fhandle 
Example 12
Project: jawfish   Author: war-and-code   File: chardetect.py    License: MIT License 6 votes vote down vote up
def description_of(lines, name='stdin'):
    """
    Return a string describing the probable encoding of a file or
    list of strings.

    :param lines: The lines to get the encoding of.
    :type lines: Iterable of bytes
    :param name: Name of file or collection of lines
    :type name: str
    """
    u = UniversalDetector()
    for line in lines:
        u.feed(line)
    u.close()
    result = u.result
    if result['encoding']:
        return '{0}: {1} with confidence {2}'.format(name, result['encoding'],
                                                     result['confidence'])
    else:
        return '{0}: no result'.format(name) 
Example 13
Project: OpenTrader   Author: OpenTrading   File: cmd2plus.py    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
def redirect_output(self, statement):
        if statement.parsed.pipeTo:
            self.kept_state = Statekeeper(self, ('stdout',))
            self.kept_sys = Statekeeper(sys, ('stdout',))
            self.redirect = subprocess.Popen(statement.parsed.pipeTo, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
            sys.stdout = self.stdout = self.redirect.stdin
        elif statement.parsed.output:
            if (not statement.parsed.outputTo) and (not can_clip):
                raise EnvironmentError('Cannot redirect to paste buffer; install ``xclip`` and re-run to enable')
            self.kept_state = Statekeeper(self, ('stdout',))
            self.kept_sys = Statekeeper(sys, ('stdout',))
            if statement.parsed.outputTo:
                mode = 'w'
                if statement.parsed.output == 2 * self.redirector:
                    mode = 'a'
                sys.stdout = self.stdout = open(os.path.expanduser(statement.parsed.outputTo), mode)
            else:
                sys.stdout = self.stdout = tempfile.TemporaryFile(mode="w+")
                if statement.parsed.output == '>>':
                    self.stdout.write(get_paste_buffer()) 
Example 14
Project: OpenTrader   Author: OpenTrading   File: cmd2plus.py    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
def do_load(self, arg=None):
        """Runs script of command(s) from a file or URL."""
        if arg is None:
            targetname = self.default_file_name
        else:
            arg = arg.split(None, 1)
            targetname, args = arg[0], (arg[1:] or [''])[0].strip()
        try:
            target = self.read_file_or_url(targetname)
        except IOError as e:
            self.perror('Problem accessing script from %s: \n%s' % (targetname, e))
            return
        keepstate = Statekeeper(self, ('stdin','use_rawinput','prompt',
                                       'continuation_prompt','current_script_dir'))
        self.stdin = target
        self.use_rawinput = False
        self.prompt = self.continuation_prompt = ''
        self.current_script_dir = os.path.split(targetname)[0]
        stop = self._cmdloop()
        self.stdin.close()
        keepstate.restore()
        self.lastcmd = ''
        return stop and (stop != self._STOP_SCRIPT_NO_EXIT) 
Example 15
Project: razzy-spinner   Author: rafasashi   File: __init__.py    License: GNU General Public License v3.0 6 votes vote down vote up
def in_idle():
    """
    @rtype: C{boolean}
    @return: true if this function is run within idle.  Tkinter
    programs that are run in idle should never call L{Tk.mainloop}; so
    this function should be used to gate all calls to C{Tk.mainloop}.

    @warning: This function works by checking C{sys.stdin}.  If the
    user has modified C{sys.stdin}, then it may return incorrect
    results.
    """
    import sys, types
    return (type(sys.stdin) == types.InstanceType and \
            sys.stdin.__class__.__name__ == 'PyShell')

##//////////////////////////////////////////////////////
##  Test code.
##////////////////////////////////////////////////////// 
Example 16
Project: razzy-spinner   Author: rafasashi   File: util.py    License: GNU General Public License v3.0 6 votes vote down vote up
def in_idle():
    """
    Return True if this function is run within idle.  Tkinter
    programs that are run in idle should never call ``Tk.mainloop``; so
    this function should be used to gate all calls to ``Tk.mainloop``.

    :warning: This function works by checking ``sys.stdin``.  If the
        user has modified ``sys.stdin``, then it may return incorrect
        results.
    :rtype: bool
    """
    import sys
    return sys.stdin.__class__.__name__ in ('PyShell', 'RPCProxy')

##########################################################################
# PRETTY PRINTING
########################################################################## 
Example 17
Project: pwnypack   Author: edibledinos   File: flow.py    License: MIT License 6 votes vote down vote up
def interact(self):
        """
        Interact with the socket. This will send all keyboard input to the
        socket and input from the socket to the console until an EOF occurs.
        """

        sockets = [sys.stdin, self.channel]
        while True:
            ready = select.select(sockets, [], [])[0]

            if sys.stdin in ready:
                line = sys.stdin.readline().encode('latin1')
                if not line:
                    break
                self.write(line)

            if self.channel in ready:
                self.read(1, echo=True) 
Example 18
Project: container-agent   Author: googlearchive   File: run_containers.py    License: Apache License 2.0 6 votes vote down vote up
def main():
    if len(sys.argv) > 2:
        Fatal('usage: %s [containers.yaml]' % sys.argv[0])

    if len(sys.argv) == 2:
        with open(sys.argv[1], 'r') as fp:
            config = yaml.load(fp)
    else:
        config = yaml.load(sys.stdin)

    syslog.openlog(PROGNAME)
    LogInfo('processing container manifest')

    CheckVersion(config)

    all_volumes = LoadVolumes(config.get('volumes', []))
    user_containers = LoadUserContainers(config.get('containers', []),
                                         all_volumes)
    CheckGroupWideConflicts(user_containers)

    if user_containers:
        infra_containers = LoadInfraContainers(user_containers)
        RunContainers(infra_containers + user_containers) 
Example 19
Project: firefox_decrypt   Author: unode   File: firefox_decrypt.py    License: GNU General Public License v3.0 6 votes vote down vote up
def ask_password(profile, interactive):
    """
    Prompt for profile password
    """
    if not PY3:
        profile = profile.encode(SYS_ENCODING)

    passmsg = "\nMaster Password for profile {0}: ".format(profile)

    if sys.stdin.isatty() and interactive:
        passwd = getpass(passmsg)

    else:
        # Ability to read the password from stdin (echo "pass" | ./firefox_...)
        if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
            passwd = sys.stdin.readline().rstrip("\n")
        else:
            LOG.warning("Master Password not provided, continuing with blank password")
            passwd = ""

    return py2_decode(passwd) 
Example 20
Project: misp42splunk   Author: remg427   File: search_command.py    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
def process(self, argv=sys.argv, ifile=sys.stdin, ofile=sys.stdout):
        """ Process data.

        :param argv: Command line arguments.
        :type argv: list or tuple

        :param ifile: Input data file.
        :type ifile: file

        :param ofile: Output data file.
        :type ofile: file

        :return: :const:`None`
        :rtype: NoneType

        """
        if len(argv) > 1:
            self._process_protocol_v1(argv, ifile, ofile)
        else:
            self._process_protocol_v2(argv, ifile, ofile) 
Example 21
Project: misp42splunk   Author: remg427   File: search_command.py    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
def process(self, argv=sys.argv, ifile=sys.stdin, ofile=sys.stdout):
        """ Process data.

        :param argv: Command line arguments.
        :type argv: list or tuple

        :param ifile: Input data file.
        :type ifile: file

        :param ofile: Output data file.
        :type ofile: file

        :return: :const:`None`
        :rtype: NoneType

        """
        if len(argv) > 1:
            self._process_protocol_v1(argv, ifile, ofile)
        else:
            self._process_protocol_v2(argv, ifile, ofile) 
Example 22
Project: supervisor-logging   Author: infoxchange   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def main():
    """
    Main application loop.
    """

    env = os.environ

    try:
        host = env['SYSLOG_SERVER']
        port = int(env['SYSLOG_PORT'])
        socktype = socket.SOCK_DGRAM if env['SYSLOG_PROTO'] == 'udp' \
            else socket.SOCK_STREAM
    except KeyError:
        sys.exit("SYSLOG_SERVER, SYSLOG_PORT and SYSLOG_PROTO are required.")

    handler = SysLogHandler(
        address=(host, port),
        socktype=socktype,
    )
    handler.setFormatter(PalletFormatter())

    for event_headers, event_data in supervisor_events(sys.stdin, sys.stdout):
        event = logging.LogRecord(
            name=event_headers['processname'],
            level=logging.INFO,
            pathname=None,
            lineno=0,
            msg=event_data,
            args=(),
            exc_info=None,
        )
        event.process = int(event_headers['pid'])
        handler.handle(event) 
Example 23
Project: clikit   Author: sdispater   File: standard_input_stream.py    License: MIT License 5 votes vote down vote up
def __init__(self):  # type: () -> None
        super(StandardInputStream, self).__init__(sys.stdin) 
Example 24
Project: drydock   Author: airshipit   File: image_tags.py    License: Apache License 2.0 5 votes vote down vote up
def main():
    config = read_config(sys.stdin, os.environ)
    tags = build_tags(config)

    for tag in tags:
        print(tag) 
Example 25
Project: kaldi-python-io   Author: funcwj   File: inst.py    License: Apache License 2.0 5 votes vote down vote up
def _fclose(fname, fd):
    """
    Extend file close function, to support
        1) "-", which means stdin/stdout
        2) "$cmd |" which means pipe.stdout
        3) None type
    """
    if fname != "-" and fd and fname[-1] != "|":
        fd.close() 
Example 26
Project: kaldi-python-io   Author: funcwj   File: inst.py    License: Apache License 2.0 5 votes vote down vote up
def parse_scps(scp_path,
               value_processor=lambda x: x,
               num_tokens=2,
               restrict=True):
    """
    Parse kaldi's script(.scp) file with supported for stdin
    WARN: last line of scripts could not be None and with "\n" end
    """
    scp_dict = dict()
    line = 0
    with ext_open(scp_path, "r") as f:
        for raw_line in f:
            scp_tokens = raw_line.strip().split()
            line += 1
            if scp_tokens[-1] == "|":
                key, value = scp_tokens[0], " ".join(scp_tokens[1:])
            else:
                token_len = len(scp_tokens)
                if num_tokens >= 2 and token_len != num_tokens or restrict and token_len < 2:
                    raise RuntimeError(f"For {scp_path}, format error " +
                                       f"in line[{line:d}]: {raw_line}")
                if num_tokens == 2:
                    key, value = scp_tokens
                else:
                    key, value = scp_tokens[0], scp_tokens[1:]
            if key in scp_dict:
                raise ValueError(
                    f"Duplicate key \'{key}\' exists in {scp_path}")
            scp_dict[key] = value_processor(value)
    return scp_dict 
Example 27
Project: csv2json   Author: oplatek   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def convert(csv, json, **kwargs):
    '''Convert csv to json.

    csv:  filename or file-like object
    json: filename  or file-like object


    if csv is '-' or None:
        stdin is used for input
    if json is '-' or None:
        stdout is used for output
    '''

    csv_local, json_local = None, None
    try:
        if csv == '-' or csv is None:
            csv = sys.stdin
        elif isinstance(csv, str):
            csv = csv_local = open(csv, 'r')

        if json == '-' or json is None:
            json = sys.stdout
        elif isinstance(json, str):
            json = json_local = open(json, 'w')

        data = load_csv(csv, **kwargs)
        save_json(data, json, **kwargs)
    finally:
        if csv_local is not None:
            csv_local.close()
        if json_local is not None:
            json_local.close() 
Example 28
Project: CAMISIM   Author: CAMI-challenge   File: anonymizer.py    License: Apache License 2.0 5 votes vote down vote up
def anonymize_sequences(
		self, mapping, input_stream=sys.stdin, output_stream=sys.stdout,
		sequence_prefix='', file_format="fasta"):
		"""
			Anonymize sequences and write a mapping file

			@attention: only 'fasta' and 'fastq' supported

			@param mapping: output stream for sequence id mapping
			@type mapping: file | io.FileIO | StringIO.StringIO
			@param input_stream: Input stream of fasta format data
			@type input_stream: file | io.FileIO | StringIO.StringIO
			@param output_stream: Output stream of anonymous fasta format data
			@type output_stream: file | io.FileIO | StringIO.StringIO
			@param sequence_prefix: Prefix of the anonymous sequence id.
			@type sequence_prefix: basestring
			@param file_format: Fasta format of input and output. Either 'fasta' or 'fastq'.
			@type file_format: basestring

			@return: None
			@rtype: None
		"""
		assert self.is_stream(input_stream)
		assert self.is_stream(output_stream)
		assert self.is_stream(mapping)
		assert isinstance(sequence_prefix, basestring)
		assert isinstance(file_format, basestring)
		file_format = file_format.lower()
		assert file_format in self._legal_formats

		sequence_counter = 0
		for seq_record in SeqIO.parse(input_stream, file_format):
			anonymous_id = "{pre}{ct}".format(pre=sequence_prefix, ct=sequence_counter)
			map_line = "{oldid}\t{newid}\n".format(oldid=seq_record.id, newid=anonymous_id)
			mapping.write(map_line)
			seq_record.id = anonymous_id
			seq_record.description = ''
			output_stream.write(seq_record.format(file_format))
			sequence_counter += 1 
Example 29
Project: CAMISIM   Author: CAMI-challenge   File: ref_seq_gen.py    License: Apache License 2.0 5 votes vote down vote up
def findPlasmids(outPlasmidFilePath):
    """
        Read sequence descriptions from a DBK files (stdin), output sequence ids (record.id) if the corresponding
        description contain "plasmid".
        Plasmids can be also within the sequences!
    """
    # append to a file if it already exists
    if os.path.isfile(outPlasmidFilePath):
        outFileMode = 'a'
    else:
        outFileMode = 'w'
    outBuffer = csv.OutFileBuffer(outPlasmidFilePath, bufferText=False, fileOpenMode=outFileMode)

    recordCount = 0
    plasmidCount = 0

    for record in SeqIO.parse(sys.stdin, "genbank"):
        recordCount += 1

        if string.find(record.description, 'plasmid') != -1:
            outBuffer.writeText(str(str(record.id) + '\n'))
            plasmidCount += 1

    outBuffer.close()
    print 'file, records, plasmids:', outPlasmidFilePath, recordCount, plasmidCount
    #for feature in record.features:
    #    if feature.type == "source": 
Example 30
Project: knob   Author: francozappa   File: cmds.py    License: MIT License 5 votes vote down vote up
def _spawnWireshark(self):
                # Global Header Values
                PCAP_GLOBAL_HEADER_FMT = '@ I H H i I I I '
                PCAP_MAGICAL_NUMBER = 2712847316
                PCAP_MJ_VERN_NUMBER = 2
                PCAP_MI_VERN_NUMBER = 4
                PCAP_LOCAL_CORECTIN = 0
                PCAP_ACCUR_TIMSTAMP = 0
                PCAP_MAX_LENGTH_CAP = 65535
                PCAP_DATA_LINK_TYPE = self.pcap_data_link_type

                pcap_header = struct.pack('@ I H H i I I I ',
                        PCAP_MAGICAL_NUMBER,
                        PCAP_MJ_VERN_NUMBER,
                        PCAP_MI_VERN_NUMBER,
                        PCAP_LOCAL_CORECTIN,
                        PCAP_ACCUR_TIMSTAMP,
                        PCAP_MAX_LENGTH_CAP,
                        PCAP_DATA_LINK_TYPE)

                self.wireshark_process = subprocess.Popen(
                        ["wireshark", "-k", "-i", "-"], 
                        stdin=subprocess.PIPE)

                self.wireshark_process.stdin.write(pcap_header)

                self.poll_timer = Timer(3, self._pollTimer, ())
                self.poll_timer.start()