Python calls the Linux Shell script and returns a result example.

Source: Internet
Author: User
#! /Usr/bin/Python #-*-coding: cp936-*-import re; import OS; import sys; if (_ name __= = "_ main _"): P = Re. compile ('(^ \ s + | \ s + $)'); pdigit = Re. compile ('^ \ D +'); delimiter = '\ T'; strdict = 'dict. dat '; strcontigency = 'contigency. dat '; str_input = STR (sys. argv [1]); str_weight = STR (sys. argv [2]); str_output = STR (sys. argv [3]); fid_input = file (str_input, 'R'); fid_output = file (str_output, 'w'); KEYWORDS = []; keywordstmp = fid_input. Readlines (); For m in keywordstmp: mykey = P. sub ('', m); keywords. append (mykey); for keyword in keywords: Results = []; # results. append (keyword); command = ''; command = 'grep-N ^ % S $ % s' % (keyword, strdict); tmpcol = OS. popen (command ). readlines (); temp = P. sub ('', tmpcol [0]); temps = temp. split (':'); linenum = int (temps [0]) + 1; command = "sed-n' % DP '% s" % (linenum, strdict ); tmpcol = OS. popen (command ). readlines (); temp = P. Sub ('', tmpcol [0]); # indicate how?docs key indexed; totalindexed = temp; # results. append (temp); command = 'grep-N ^ % S $ % s' % (keyword, str_weight); tmpcol = OS. popen (command ). readlines (); temp = P. sub ('', tmpcol [0]); temps = temp. split (':'); linenum = int (temps [0]) + 2; command = "sed-n '% DP' % s" % (linenum, str_weight ); tmpcol = OS. popen (command ). readlines (); temp = P. sub ('', tmpcol [0]); temps = temp. split (''); myclas S = temps [0] # results. append (myclass); command = "grep-n '^ % S % s' % s" % (keyword, myclass, strcontigency); tmpcol = OS. popen (command ). readlines (); temp = P. sub ('', tmpcol [0]); temps = temp. split (':'); temp1 = P. sub ('', temps [1]); Results = temp1.split (''); results. append (totalindexed); # numin = m [1]; # numnotin = m [2]; # print numin; # print numnotin; # print results # S = raw_input ('Please enter'); # results. append (numin );# Results. append (numnotin); myline = delimiter. join (results); fid_output.write (myline); fid_output.write ('\ n'); print myline; fid_input.close (); fid_output.close (); print' % s has finished, congratulations! '% STR (SYS. argv [0]);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.