-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathRunCMD.py
53 lines (45 loc) · 1.77 KB
/
RunCMD.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import subprocess,os,sys
def run_cmd(cmd, shell = True, universal_newlines = False):
output_info=[]
output_err=[]
cmd = os.path.join(get_ffmpeg_path(), cmd)
print('执行cmd:\n%s' % cmd)
with subprocess.Popen(cmd,
shell = shell,
universal_newlines = universal_newlines,
stdout = subprocess.PIPE,
stdin = subprocess.PIPE,
stderr = subprocess.PIPE
) as p:
while True:
info=p.stdout.read()
# print(dir(p.stderr))
print(info)
err=p.stderr.read()
print(err)
# if not info and not err:
if info == b'' and err == b'':
if p.poll() is not None:
break
else:
output_info.append(info)
output_err.append(err)
return output_err, output_info
def get_ffmpeg_path():
datadir = ''
subdir = os.path.join('ffmpeg-shared','bin')
if getattr(sys, 'frozen', False):
# The application is frozen
datadir = os.path.dirname(sys.executable)
else:
# The application is not frozen
# Change this bit to match where you store your data files:
datadir = os.path.dirname(__file__)
datadir = os.path.join(datadir, subdir)
datadir = os.path.abspath(datadir)
print(datadir)
#如果存在ffmpeg.exe
if os.path.isfile(os.path.join(datadir, 'ffmpeg.exe')):
return datadir
#兼容环境变量设置
return ''