【发布时间】:2023-12-30 03:15:01
【问题描述】:
我对 python 脚本很陌生,我正在尝试实现 shell cmd 的 python 等价物
echo -e "abc\ncde" >file1
file1 的内容如下所示:
abc
cde
我的 python 脚本有:
cmd = "echo -e \"abc\ncde\" >file1"
os.system(cmd)
但是,执行此操作时,我的 file1 如下所示:
-e abc
cde
'-e` 是 echo 将 \n 识别为换行符的选项,不应将其写入文件。有没有办法解决这个问题?
谢谢!
【问题讨论】:
标签: python scripting subprocess os.system