python之shell
import subprocess # 返回命令执行结果
# result = subprocess.call('ls -l', shell=True)
# result = subprocess.call(['ls', '-l'], shell=False)
# print(result) # subprocess.check_call(["ls", "-l"])
# subprocess.check_call("exit 1", shell=True) # 好像没Python废弃了
subprocess.check_output(["echo", "Hello World!"], shell=False)
subprocess.check_output("exit 1", shell=True) # 、执行复杂的系统相关命令 # )切换目录再执行命令
obj = subprocess.Popen("mkdir t3", shell=True, cwd='/home/dev',) # )有多行且复杂的命令使用三个接口
# obj = subprocess.Popen(["python"], stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
# obj.stdin.write("print(1)\n") # 传命令接口
# obj.stdin.write("print(2)")
# obj.stdin.close()
#
# cmd_out = obj.stdout.read() # 读接口
# obj.stdout.close()
# cmd_error = obj.stderr.read() # 读错误接口
# obj.stderr.close()
#
# print(cmd_out)
# print(cmd_error) # )一次读输出
# obj = subprocess.Popen(["python"], stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
# obj.stdin.write("print(1)\n")
# obj.stdin.write("print(2)")
#
# out_error_list = obj.communicate()
# print(out_error_list) # )简单写法
# obj = subprocess.Popen(["python"], stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
# out_error_list = obj.communicate('print("hello")')
# print(out_error_list)
python之shell的更多相关文章
- python 调用 shell 命令方法
python调用shell命令方法 1.os.system(cmd) 缺点:不能获取返回值 2.os.popen(cmd) 要得到命令的输出内容,只需再调用下read()或readlines()等 ...
- 【转】为eclipse安装python、shell开发环境和SVN插件
原文网址:http://www.crazyant.net/1185.html eclipse是一个非常好用的IDE,通常来说我们都用eclipse来开发JAVA程序,为了让开发python.shell ...
- python执行shell获取硬件参数写入mysql
最近要获取服务器各种参数,包括cpu.内存.磁盘.型号等信息.试用了Hyperic HQ.Nagios和Snmp,它们功能都挺强大的,但是于需求不是太符,亦或者太heavy. 于是乎想到用python ...
- python调用shell, shell 引用python
python 调用 shell get_line_num="wc -l as_uniq_info | awk '{print $1}'" ###get the lines of & ...
- python 调用shell命令三种方法
#!/usr/bin/python是告诉操作系统执行这个脚本的时候,调用/usr/bin下的python解释器: #!/usr/bin/env python这种用法是为了防止操作系统用户没有将pyth ...
- python编写shell脚本详细讲解
python编写shell脚本详细讲解 那,python可以做shell脚本吗? 首先介绍一个函数: os.system(command) 这个函数可以调用shell运行命令行command并且返回它 ...
- python 调用 shell 命令
记录 python 调用 shell 命令的方法 加载 os 模块, 使用 os 类 import os; os.system("ls /");
- 为eclipse安装python、shell开发环境和SVN插件
http://www.crazyant.net/1185.html 为eclipse安装python.shell开发环境和SVN插件 2013/08/27 by Crazyant 暂无评论 eclip ...
- Python 调用 Shell脚本的方法
Python 调用 Shell脚本的方法 1.os模块的popen方法 通过 os.popen() 返回的是 file read 的对象,对其进行读取 read() 的操作可以看到执行的输出. > ...
- 记一次对python反弹shell的分析
前言 昨天学习了反弹shell,对python弹shell产生了一些疑惑 python -c 'import socket,subprocess,os;s=socket.socket(socket.A ...
随机推荐
- properties配置文件读取操作总结【java笔记】
声明:本文所有例子中的 properties 文件均放在 src 目录下,ecclipse 软件自动增加 一.基本概念 1.1 properties文件,存储格式 键=值. properties文件 ...
- LeetCode专题-Python实现之第7题:Reverse Integer
导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...
- C++STL模板库适配器之优先级队列
目录 适配器之优先级队列 一丶优先级队列简介(priority_queue) 二丶优先级队列代码演示 1.优先级队列代码以及使用简介 适配器之优先级队列 一丶优先级队列简介(priority_queu ...
- 重复造轮子,编写一个轻量级的异步写日志的实用工具类(LogAsyncWriter)
一说到写日志,大家可能推荐一堆的开源日志框架,如:Log4Net.NLog,这些日志框架确实也不错,比较强大也比较灵活,但也正因为又强大又灵活,导致我们使用他们时需要引用一些DLL,同时还要学习各种用 ...
- Log4Net使用学习笔记
项目源文件下载https://files.cnblogs.com/files/ckym/Log4NetTestSourceCode.zip Log4net是一款非常好用的日志记录的框架,使用它可以实现 ...
- IOC的理解,整合AOP,解耦对Service层和Dal层的依赖
DIP依赖倒置原则:系统架构时,高层模块不应该依赖于低层模块,二者通过抽象来依赖依赖抽象,而不是细节 贯彻依赖倒置原则,左边能抽象,右边实例化的时候不能直接用抽象,所以需要借助一个第三方 高层本来是依 ...
- .Net基础——程序集与CIL
1. 程序集和CIL: 程序集是由.NET语言的编译器接受源代码文件产生的输出文件,通常分为 exe和dll两类,其中exe包含Main入口方法可以双击执行,dll则需要被其他程序集调用执行. CIL ...
- 从零开始学安全(三十八)●cobaltstrike生成木马抓肉鸡
链接:https://pan.baidu.com/s/1qstCSM9nO95tFGBsnYFYZw 提取码:w6ih 上面是工具 需要java jdk 在1.8.5 以上 实验环境windows ...
- 记录 FTPClient 超时处理的相关问题
apache 有个开源库:commons-net,这个开源库中包括了各种基础的网络工具类,我使用了这个开源库中的 FTP 工具. 但碰到一些问题,并不是说是开源库的 bug,可能锅得算在产品头上吧,各 ...
- Hacking /dev/random: Pipe
1) 下载镜像,虚拟机启动 https://download.vulnhub.com/devrandom/pipe.ova 2) nmap 扫描探测 Nmap 扫描开路: ╰─ nmap -Pn -s ...