目前使用到的有两种方式:os.system()和os.popen()

import os
os.system('cd e:cjx') #调用后返回执行结果状态

如果想获得返回结果,则使用以下方式:

import os
res = os.popen('dir').readlines()
print(res)

 如果要连续执行多个命令:

import os
os.system('e: & cd e:\cjx & dir')

python 调用shell或windows命令的更多相关文章

  1. python 调用shell命令三种方法

    #!/usr/bin/python是告诉操作系统执行这个脚本的时候,调用/usr/bin下的python解释器: #!/usr/bin/env python这种用法是为了防止操作系统用户没有将pyth ...

  2. 用Python调用Shell命令

    Python经常被称作“胶水语言”,因为它能够轻易地操作其他程序,轻易地包装使用其他语言编写的库,也当然可以用Python调用Shell命令. 用Python调用Shell命令有如下几种方式: 第一种 ...

  3. python 调用 shell 命令方法

    python调用shell命令方法 1.os.system(cmd) 缺点:不能获取返回值 2.os.popen(cmd) 要得到命令的输出内容,只需再调用下read()或readlines()等   ...

  4. python 调用 shell 命令

    记录 python 调用 shell 命令的方法 加载 os 模块, 使用 os 类 import os; os.system("ls /");

  5. Python调用shell命令常用方法

    Python调用shell指令 方法一.使用os模块的system方法:os.system(cmd),其返回值是shell指令运行后返回的状态码,int类型,0表示shell指令成功执行,256表示未 ...

  6. python调用shell, shell 引用python

    python 调用 shell get_line_num="wc -l as_uniq_info | awk '{print $1}'" ###get the lines of & ...

  7. Python 调用 Shell脚本的方法

    Python 调用 Shell脚本的方法 1.os模块的popen方法 通过 os.popen() 返回的是 file read 的对象,对其进行读取 read() 的操作可以看到执行的输出. > ...

  8. python 调用shell命令的方法

    在python程序中调用shell命令,是件很酷且常用的事情…… 1. os.system(command) 此函数会启动子进程,在子进程中执行command,并返回command命令执行完毕后的退出 ...

  9. python调用shell命令

    1.subprocess介绍 官方推荐 subprocess模块,os.system(command) 这个废弃了 亲测 os.system 使用sed需要进行字符转义,非常麻烦 python3 su ...

随机推荐

  1. JAVA JNI学习

    JAVA JNI   JNI是Java Native Interface的缩写,中文为JAVA本地调用.从Java1.1开始,Java Native Interface(JNI)标准成为java平台的 ...

  2. How Many Tables(POJ 1213 求连通分量)

    How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  3. "windows 正在启动"

    xp 在cmd下使用了control userpasswords2 设定开机不需要密码之后,开机停留在“window正在启动”,无法进入.估计是设置的时候密码输入错误了( 并不会提示你错误:() 在停 ...

  4. C# 调用 Web Service

    Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量级的独立的通讯技术.是:通过SOAP ...

  5. PYCURL ERROR 6 - “Couldn't resolve host 'mirrorlist.centos.org'”

    在虚拟机上安装的CentOS,估计是网络配置问题,导致yum update和yum install之类的功能的用不了.出现标题上面的错误. ifdown [network_adapter] ifup ...

  6. setTimeout()使用

    Basic setTimeout() Example setTimeout(function() {       // Do something after 5 seconds }, ); Tip:  ...

  7. Subsets 解答

    Question Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a su ...

  8. OpenCV视屏跟踪

    #include <stdio.h> #include <iostream> #include "opencv2/imgproc/imgproc.hpp" ...

  9. java Socket使用注意

    Socket s = new Socket(ia, port); BufferedOutputStream bufOut = new BufferedOutputStream(s.getOutputS ...

  10. 【转】Android LCD(一):LCD基本原理篇

    关键词:android LCD TFT 液晶 偏光片 彩色滤光片  背光 平台信息:内核:linux2.6/linux3.0系统:android/android4.0 平台:samsung exyno ...