Skip to content

Commit e8ddfa4

Browse files
author
zhenwei-li
committed
适配 3.x 字符编码规则
1 parent 377b2e7 commit e8ddfa4

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

src/com/dvsnier/process/execute.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# -- coding:utf-8 --
22

3+
import datetime
34
# import logging
45
import os
6+
import platform
57
import time
8+
import sys
69
import subprocess
7-
import platform
10+
811
from com.dvsnier.directory.common_dir import generate_complex_file_name
9-
import datetime
1012

1113

1214
def execute(cmds, quiet=True):
@@ -17,10 +19,7 @@ def execute(cmds, quiet=True):
1719
# (p.pid, os.getppid(), type(p), id(p)))
1820
processes = [p]
1921
for x in cmds[1:]:
20-
p = subprocess.Popen(x,
21-
stdin=p.stdout,
22-
stdout=subprocess.PIPE,
23-
shell=True)
22+
p = subprocess.Popen(x, stdin=p.stdout, stdout=subprocess.PIPE, shell=True)
2423
# logging.debug(
2524
# 'the current sub process pid(cwd: %s, ppid: %s, id: %s%d).' %
2625
# (p.pid, os.getppid(), type(p), id(p)))
@@ -39,7 +38,11 @@ def execute(cmds, quiet=True):
3938
print('\r'),
4039
msg = '[%.5f] -> %s' % (end - start, ' | '.join(cmds))
4140
print(msg)
42-
content = output.rstrip('\n')
41+
content = ''
42+
if sys.version_info.major > 2:
43+
content = str(output.rstrip(bytes('\n', encoding='utf-8')))
44+
else:
45+
content = output.rstrip('\n')
4346
# logging.debug('the current run process pid(cwd: %s, ppid: %s, id: %s%d).' %
4447
# (p.pid, os.getppid(), type(p), id(p)))
4548
return content
@@ -57,11 +60,8 @@ def trace(cmds):
5760
file.write('\n')
5861
file.write(
5962
str('the current timestamp: {timestamp}\n'.format(
60-
timestamp=datetime.datetime.now().strftime(
61-
'%Y-%m-%d %H:%M:%S.%f'))))
62-
file.write(
63-
str('the current command: [{cmd}].\n'.format(
64-
cmd=' | '.join(command))))
63+
timestamp=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f'))))
64+
file.write(str('the current command: [{cmd}].\n'.format(cmd=' | '.join(command))))
6565
# file.write(execute(command, quiet=False))
6666
file.write(execute(command, quiet=True))
6767
file.write('\n')

0 commit comments

Comments
 (0)