subprocess

Making python wait until subprocess.call has finished its command

一笑奈何 提交于 2020-03-25 17:52:11
问题 So this question is following on from this (Read comments aswell as that is the path I took). I just want the first call robocopy to finish executing before moving on to the rest of the code. As I want the second robocopy to just skip all of the files as they have already been copied over. However what is happening is that the rest of the script will run (ie starts the second robocopy) while the first robocopy is copying over the files. Below is the code: call(["start", "cmd", "/K", "RoboCopy

TypeError: 'function' object is not subscriptable Python with ffmpeg

早过忘川 提交于 2020-03-25 16:17:22
问题 clips = [] def clipFinder(CurrentDir, fileType): clips.clear() for r,d,f in os.walk(CurrentDir): for file in f: if fileType in file: clips.append(r+file) random.shuffle(clips) def removeVods(r): for f in clips: if 'vod' in clips: os.remove(r+f) def clipString(): string = 'intermediate' clipList = [] clipNum = 1 for f in clips: clipList.append(string+str(clipNum)+'.ts'+'|') clipNum+=1 string1 = ''.join(clipList) string2 = string1[0:len(string1)-1] return string2 def concatFiles(): clipFinder('

Py西游攻关之模块

萝らか妹 提交于 2020-03-25 04:52:47
Py西游攻关之模块 模块&包(* * * * *) 模块(modue)的概念: 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护。 为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文件包含的代码就相对较少,很多编程语言都采用这种组织代码的方式。在Python中,一个.py文件就称之为一个模块(Module)。 使用模块有什么好处? 最大的好处是大大提高了代码的可维护性。 其次,编写代码不必从零开始。当一个模块编写完毕,就可以被其他地方引用。我们在编写程序的时候,也经常引用其他模块,包括Python内置的模块和来自第三方的模块。 所以,模块一共三种: python标准库 第三方模块 应用程序自定义模块 另外,使用模块还可以避免函数名和变量名冲突。相同名字的函数和变量完全可以分别存在不同的模块中,因此,我们自己在编写模块时,不必考虑名字会与其他模块冲突。但是也要注意,尽量不要与内置函数名字冲突。 模块导入方法 1 import 语句 1 import module1[, module2[,... moduleN] 当我们使用import语句的时候,Python解释器是怎样找到对应的文件的呢?答案就是解释器有自己的搜索路径,存在sys.path里。   1 2 [' ', ' / usr / lib /

常用模块介绍

孤街醉人 提交于 2020-03-25 03:10:27
subprocess模块 它是可以远程操作主机,模拟shell命令 'dir'是windows上查看任务的命令 import subprocess obj = subprocess.Popen('dir', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #Popen是模拟cmd命令,'dir'是windows上查看任务的命令,shell=True是指可以用shell命令了, 输出和错误,放到管道(PIPE)里 # print(obj.stdout.read().decode('gbk')) #打印输出的内容 # print(obj.stderr.read().decode('gbk')) #打印错误的内容 res = obj.stdout.read() + obj.stderr.read() #错误和输入放到一起给变量res print(res.decode('gbk')) #打印res 在linux里可以创建python脚本,写入 import subprocess obj = subprocess.Popen('ls;lsblk', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #Popen是模拟cmd命令,'dir

How can I simulate a key press in a Python subprocess?

别说谁变了你拦得住时间么 提交于 2020-03-23 02:03:55
问题 The scenario is, I have a Python script which part of it is to execute an external program using the code below: subprocess.run(["someExternalProgram", "some options"], shell=True) And when the external program finishes, it requires user to "press any key to exit". Since this is just a step in my script, it would be good for me to just exit on behalf of the user. Is it possible to achieve this and if so, how? 回答1: from subprocess import Popen, PIPE p = Popen(["someExternalProgram", "some

How can I simulate a key press in a Python subprocess?

空扰寡人 提交于 2020-03-23 02:02:31
问题 The scenario is, I have a Python script which part of it is to execute an external program using the code below: subprocess.run(["someExternalProgram", "some options"], shell=True) And when the external program finishes, it requires user to "press any key to exit". Since this is just a step in my script, it would be good for me to just exit on behalf of the user. Is it possible to achieve this and if so, how? 回答1: from subprocess import Popen, PIPE p = Popen(["someExternalProgram", "some

用Python在Tomcat成功启动后自动打开浏览器访问Web应用

给你一囗甜甜゛ 提交于 2020-03-20 14:53:24
3 月,跳不动了?>>> 前提条件 Windows Python 2.7 需设置 CATALINA_HOME 环境变量 放码过来 # -*- coding: utf-8 -* import os import time import subprocess tomcatStartFilePath = 'C:\\tomcat\\apache-tomcat-7.0.90-windows-x64\\apache-tomcat-7.0.90\\bin\\startup.bat' browserPath = 'C:\\Users\\Administrator.USER-20180302VA\\AppData\\Local\\360Chrome\\Chrome\\Application\\360chrome.exe' appAddress = "http://localhost:8080/nice" # 启动 tomcat,注意要设置CATALINA_HOME的环境变量 subprocess.Popen(tomcatStartFilePath, shell=True) print 'Starting tomcat...' time.sleep(15) # 启动15s后, 轮询 8080端口是否启用 print 'Polling...' startBrowerFalg = False

《自拍教程45》Python_adb实时监控Logcat日志

自闭症网瘾萝莉.ら 提交于 2020-03-19 00:44:00
接上一篇: adb命令_一键截取logcat日志 , 有一天, 系统稳定性开发负责人找到我,希望我能在跑android 系统monkey的时候, 实时监控logcat的输出,如果一旦发现“java.lang.NullPointerException"空指针异常, 则立刻用adb bugreport命令导出当时log压缩包出来。 准备阶段 adb logcat -v threadtime > D:\logcat_20200310_101112.txt可以打印按线程时间log并保存到一个文件。 由于adb logcat命令是一个持续输出的命令,它如果没被销毁(杀进程),会一直持续截取下去。 subprocess.Popen()类是支持通过stdout=subprocess.PIPE来持续获取输出的并按行读取。 adb bugreport只是一个命令,可以打包当时的tombstone, getprop, proc,cache等信息。 Python批处理脚本形式 # coding=utf-8 import os import re import subprocess command = "adb logcat -v threadtime" # 具体命令 keyword_reg = r".*java.lang.NullPointerException.*" # 正则表达式 #

Python Popen().stdout.read() hang

牧云@^-^@ 提交于 2020-03-17 08:46:27
问题 I'm trying to get output of another script, using Python's subprocess.Popen like follows process = Popen(command, stdout=PIPE, shell=True) exitcode = process.wait() output = process.stdout.read() # hangs here It hangs at the third line, only when I run it as a python script and I cannot reproduce this in the python shell. The other script prints just a few words and I am assuming that it's not a buffer issue. Does anyone has idea about what I am doing wrong here? 回答1: You probably want to use

Python Popen().stdout.read() hang

自作多情 提交于 2020-03-17 08:44:25
问题 I'm trying to get output of another script, using Python's subprocess.Popen like follows process = Popen(command, stdout=PIPE, shell=True) exitcode = process.wait() output = process.stdout.read() # hangs here It hangs at the third line, only when I run it as a python script and I cannot reproduce this in the python shell. The other script prints just a few words and I am assuming that it's not a buffer issue. Does anyone has idea about what I am doing wrong here? 回答1: You probably want to use