我需要使用python3将临时文件写入n*x机器,以便可以从命令行读取它。
import tempfile
import subprocess
from os import path
string = 'hi *there*'
# run markdown server-side
tfile = tempfile.NamedTemporaryFile(mode='w+', suffix='.txt', prefix='prove-math-')
tfile.write(string)
fpath = tfile.name
markdown_path = path.join(LIB_DIR, 'Markdown.pl')
command = [markdown_path, fpath]
completed_process = subprocess.run(command, check=True, stdout=subprocess.PIPE)
string = completed_process.stdout.decode()
tfile.close()
print(string)
'<p>hi <em>there</em></p>'
,但实际输出为
'\n'
,这对我来说意味着
Markdown.pl
.