Several ways Python calls the shell

Source: Internet
Author: User


cmd = "Some unix command" Retcode = (cmd,shell=true)


SSH = Paramiko. Sshclient () ssh.connect (server, Username=username, Password=password) Ssh_stdin, ssh_stdout, Ssh_stderr = ssh.exec_ Command (Cmd_to_execute)


Import Spurshell = Spur. Sshshell (hostname= "localhost", username= "Bob", password= "password1") result = (["Echo", "-N", "Hello"]) print Result.output # Prints Hello


Sshprocess = subprocess. Popen ([' ssh ', <remote client>], stdin=subprocess. PIPE, stdout = subprocess.    PIPE) sshProcess.stdin.write ("ls mydirectory\n") sshProcess.stdin.write ("Echo end\n") for line in Stdout.readlines (): if line = = "end\n": Break print (line) sshProcess.stdin.write ("uptime\n") sshProcess.stdin.write ("Echo end\n") for L ine in Stdout.readlines (): if line = = "end\n": Break print (line)

This article from the "Linux and Network" blog, reproduced please contact the author!

Several ways Python calls the shell

Related Article

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: 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.