#python 3.5 , win10

引入包

#os.chdir('path')

import os

import subprocess

#https://docs.python.org/3.5/library/subprocess.html?highlight=subprocess#module-subprocess

#http://ltp.readthedocs.io/zh_CN/latest/ltptest.html

Run 1 process

p1 = subprocess.Popen('cws_cmdline --input input_file.txt ',stdout=subprocess.PIPE,stderr=subprocess.PIPE [,universal_newlines=True])

#p1 = subprocess.Popen(['cws_cmdline','--input', 'input_file.txt '],stdout=subprocess.PIPE,stderr=subprocess.PIPE)

#universal_newlinews 为 True 时,输入为 str 流,(默认)为 False 时为 byte 流

output_10 = p1.communicate()[0]  #stdin

output_11 = p1.communicate()[1]  #stderr

Run pipe-line

p1 = subprocess.Popen('cws_cmdline --input input_file.txt ',stdout=subprocess.PIPE,stderr=subprocess.PIPE)

p2 = subprocess.Popen('pos_cmdline --input no_file.txt ',stdin=p1.stdout,stdout=subprocess.PIPE,stderr=subprocess.PIPE)

p3 = subprocess.Popen('ner_cmdline --input no_file.txt ',stdin=p2.stdout,stdout=subprocess.PIPE,stderr=subprocess.PIPE)

#if call p1|2.communicate()[0|1] before p3.communicate(), pipeline will break at p1|p2, because the before stdout|stderr pipe will be extract and not use anymore

#if call p1|2.communicate()[0|1] before p3 = constructor,  will get ValueError: I/O operation on closed file

output30 = p3.communicate()[0]  #stdout

output31 = p3.communicate()[1]  #stderr

#if call p1|2.communicate()[0|1] after p3.communicate(), will get close warning.

'''  def communicate(self, input=None, timeout=None):

#...

if self.stdin:

self._stdin_write(input)

elif self.stdout:

stdout = self.stdout.read()

self.stdout.close()

elif self.stderr:

stderr = self.stderr.read()

self.stderr.close()

self.wait()

#...

'''

Run process one by one

#px.communicate()  actually run the pipe line until px, all the pipe content(p1&p2&p3.stdin&stdout&stderr pipe) will be extract and not usable any more .

#if you want to save each pipe line node's meadian content , you need to use a new pipe as   stdin=subprocess.PIPE , and use  communicate('input Popen's stdin content')

p1 = subprocess.Popen('cws_cmdline --input input_file.txt ',stdout=subprocess.PIPE,stderr=subprocess.PIPE)

output_10 = p1.communicate()[0]

output_11 = p1.communicate()[1]

str_10 = output_10.decode('utf-8')

str_11 = output_10.decode('utf-8')

p2 = subprocess.Popen('pos_cmdline --input no_file.txt ',stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)

#communicate('input Popen's stdin content once if and only if stdin==subprocess.PIPE')

output_20 = p2.communicate( bytes(str_10, encoding = 'utf-8') )[0]

output_21 = p2.communicate()[1]

# for px.communicate(), only the first time call can you set the input

#or use  "universal_newlines=True" for Popen() to process str stream

p3 = subprocess.Popen('ner_cmdline --input no_file.txt ',stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)

output_3 = p3.communicate( output20)

[output_30, output_31] = output_3

Linux系统下python代码运行shell命令的方法

方法一:os.popen #!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 使用 mkdir 命令 a = 'ls' b = os. ...

python中执行shell命令行read结果

+++++++++++++++++++++++++++++ python执行shell命令1 os.system 可以返回运行shell命令状态,同时会在终端输出运行结果 例如 ipython中运行如 ...

让你提前认识软件开发(23):怎样在C语言中运行shell命令?

第1部分 又一次认识C语言 怎样在C语言中运行shell命令? [文章摘要] Linux操作系统具备开源等诸多优秀特性,因此在很多通信类软件(主流开发语言为C语言)中,开发平台都迁移到了Linux上, ...

PHP 反引号运行Shell命令,C程序

/********************************************************************* * PHP 反引号运行Shell命令,C程序 * 说明: ...

python中执行shell命令的几个方法小结(转载)

转载:http://www.jb51.net/article/55327.htm python中执行shell命令的几个方法小结 投稿:junjie 字体:[增加 减小] 类型:转载 时间:2014- ...

java运行shell命令,chmod 777 xxx,改变权限无效的解决的方法。

在java程序中运行shell命令,改变文件的权限.能够在命令行中运行 chmod 777

Python 分页和shell命令行模式

前言 除了手动添加你的文章后外,你还可以用命令行来添加,python 自带了一种命令行 就是 shell 快速添加博文:Shell命令行模式 在你的目录下:mysite python manage.p ...

python(6)-执行shell命令

可以执行shell命令的相关模块和函数有: os.system os.spawn* os.popen*          --废弃 popen2.*           --废弃 commands.* ...

随机推荐

微软雅黑 在css里怎么写

1.首先要了解css中是如何控制字体的. font:在一个声明中设置所有字体属性: font有以下几个属性: font-style:字体样式 font-variant:字体异体 font-weight ...

【GoLang】50 个 Go 开发者常犯的错误

1. { 换行:   Opening Brace Can't Be Placed on a Separate Line 2. 定义未使用的变量:  Unused Variables 2. import ...

C# Redis实战(二)

二.Redis服务  在C# Redis实战(一)中我将所有文件拷贝到了D盘redis文件夹下,其中redis-server.exe即为其服务端程序,双击即开始运行,如图             可以 ...

Java基础7:关于Java类和包的那些事

更多内容请关注微信公众号[Java技术江湖] 这是一位阿里 Java 工程师的技术小站,作者黄小斜,专注 Java 相关技术:SSM.SpringBoot.MySQL.分布式.中间件.集群.Linux ...

MySQL PARTITION 分区

MySQL HASH分区 http://www.cnblogs.com/chenmh/p/5644496.html RANGE分区:http://www.cnblogs.com/chenmh/p/56 ...

SSHLibrary库关键字汇总

红色框的部分是设置系统用户标识符(不可缺少):$表示非超级用户  #表示超级用户

TinyMCE插件:RESPONSIVE filemanager 9 安装与配置

RESPONSIVE filemanager 功能: 文件上传 文件下载 重命名文件 删除文件 新建文件夹 为每个用户创建子目录 上传文件效果图: 浏览文件效果图: 文件说明: filemanager ...

c++之旅:模板库中的容器

容器 C++中的容器包括array, vector, list,map,set 数组 array不可变长,创建时其大小就固定了,array中可以存储各种数据类型包括对象,不过array是在栈上分配的, ...

vue入门学习示例

鄙人一直是用angular框架的,所以顺便比较了一下.

< ...

IIS Internet Information Service

Visual Studio 和 visio 都有的Web服务,IIS 发布的时候,直接可以用本机的IIS进行发布,Windos自带有Web服务,只需要配置一下,然后配上域名就OK了,简直太方便了 来自 ...

python 3.7.3 shell_Python 3 运行 shell 命令相关推荐

  1. python执行shell命令查看输出_python 运行 shell 命令并捕获输出_python_酷徒编程知识库...

    这个问题的答案取决于你使用的python 版本. 最简单的方法是使用 subprocess.check_output 函数:>>> subprocess.check_output([ ...

  2. Python 标准库之 os (获取当前目录、读取/设置环境变量、重命名文件、运行shell命令、创建/删除/查看目录文件、判断目录/文件/存在、获取绝对路径、获取文件名、获取换行符、获取路径分隔符)

    1. os与sys模块的官方解释如下: os This module provides a portable way of using operating system dependent funct ...

  3. 运行shell命令并捕获输出

    我想编写一个函数,该函数将执行shell命令并以字符串形式返回其输出,无论它是错误消息还是成功消息. 我只想获得与命令行相同的结果. 能做到这一点的代码示例是什么? 例如: def run_comma ...

  4. 解决 Jupyter notebook 运行SHELL 命令(!xxx), 出错: OSError: “/bin/bach“ shell not found

    我在JUPYTER NOTEBOOK新增加一个环境ai, 进入后,在NOTEBOOK的代码行中运行 SHELL 命令 (!pip install gradio) 出错: import os os.en ...

  5. python脚本运行命令_从Python脚本运行shell命令

    我正在尝试从 python脚本中运行一个shell命令,它需要做几件事 1. shell命令是'hspice tran.deck>! tran.lis' 2.在继续之前,脚本应该等待shell命 ...

  6. php 运行 shell命令行参数,PHP exec()在通过浏览器执行时不会执行shell命令

    我有一个PHP脚本,调用exec()执行一个命令,将PDF转换为JPG.此命令在bash中工作正常. 要抢占您的初始故障排除猜测,请注意以下事项: > safe_mode = Off >包 ...

  7. php实现linux命令,PHP在Linux下运行Shell命令

    原本在本机开发PHP的时候,Shell调用一切正常.上线的时候才反应到线上的服务器对权限做了严格的控制,一顿折腾之后梳理出在严格权限控制的Linux上如何通过Nginx/Apache 以Web的方式调 ...

  8. python是在linux系统下运行的吗_Linux系统下python代码运行shell命令的方法

    方法一:os.popen #!/usr/bin/python#-*- coding: UTF-8 -*- importos, sys#使用 mkdir 命令 a = 'ls'b= os.popen(a ...

  9. c#运行shell命令

    System.Diagnostics.Process.Start("config.txt");

最新文章

  1. yii 操作cookie
  2. java调用c库实例
  3. 11.05 scrum report
  4. mybatis中getMapper是怎么通过动态代理得到dao接口的实现类并执行mapper文件sql语句的
  5. MaCfee导致Asp.net无法发送邮件的解决办法
  6. [jQuery] jQuery中如何将数组转化为json字符串,然后再转化回来?
  7. JavaScript定义类的几种方式
  8. 内联元素,取消间隙和默认效果
  9. 如何建设一个开源图形引擎的文档网站
  10. android期末课设选题_Android课程设计报告书.doc
  11. 卸载 vista sp1
  12. Overloaded operators
  13. 牛客-kotori和糖果(哈斯图吗?)
  14. shineblink MQ-3酒精浓度探测
  15. C++分数类(类与构造)
  16. 如何设计hash函数
  17. 多进程(Linux)
  18. 非常详细的Series核心操作使用详解
  19. ​韩剧影视剪辑30天5710元,短视频大神教你如何快速变现?
  20. Linux软链接和硬链接

热门文章

  1. 2021年T电梯修理作业考试题库及T电梯修理实操考试视频
  2. 《Python语言程序设计》王恺 机械工业出版社 第二章课后习题答案
  3. GAMES101作业3-遇到的各种问题及解决方法
  4. Vue学习笔记-Router死活跳不过去子路由
  5. 2018-2019-2 网络对抗技术 20165337 Exp6 信息搜集与漏洞扫描
  6. 【计算机视觉 | 目标检测】arxiv 计算机视觉关于目标检测的学术速递(6月 23 日论文合集)
  7. 一个资源 C2C 的资源平台
  8. 中国新季度智能手机市场份额发布,看完只想说心疼三星
  9. MAC vim 每次打开报错 E1208: -complete used without allowing argumentsError
  10. python识别花草_吴裕雄 python神经网络 花朵图片识别(9)