Python invokes shell, shell references python

Source: Internet
Author: User

Python Call Shell

get_line_num= "Wc-l As_uniq_info | awk ' {print '} ' "# # #get the lines of" As_uniq_info "
Line_num = os.popen(get_line_num). read (). strip (' \ n ')

Get_line_num a command that executes as a shell, gets the number of lines of file As_uniq_info file

Os.popen (get_line_num): Execute shell

Get_line_num = Os.popen (get_line_num). Read (): Call read, assign to Get_line_num, at which point the get_line_num contains a newline character ("\ n").

Os.popen (Get_line_num). read (). strip (' \ n '): Remove line break

Shell references Python variables

Line_num = Os.popen (get_line_num)

The get_line_num variable in Python is referenced.

Python references the value in the shell

Line_num = Os.popen (get_line_num). Read ()

After executing the shell, assign a value to the variable in Python via the Read () function line_num

Python invokes shell, shell references python

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.