【发布时间】:2018-11-27 10:53:00
【问题描述】:
对于在 linux shell 中执行下面的 SED 命令,我没有问题。但是要在 python-2 环境中运行它,我有问题。
我想在 HTML linux 文件中的 href=part1 行之后添加以下行。
CMDD = "sed -i '/href=part1/a \n\t\t<tr>\n\t\t <td>%s</td>\n\t\t <td>%s</td>\n\t\t <td>%s</td>\n\t\t <td>%s</td>\n\t\t <td>%s</td>\n\t\t <td>%s</td>\n\t\t <td>%s</td>\n\t\t <td>%s</td>\n\t\t</tr>' /root/var/www/html/start/index.html" %(logs[0], logs[1], logs[2], logs[3], logs[4], logs[5], logs[6], logs[7])
res = subprocess.Popen([CMDDD], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
print res
运行后出现以下错误:
('', "sed: -e expression #1, char 18: unknown command: `
我在终端内没有任何问题(例如):
sed -i "/href=part1/a <tr>\n\t\t <td>AliReza</td>\n\t\t <td>David</td>\n\t\t </tr>" tables.html
【问题讨论】: