我在编写os.system()
执行的ruby脚本输出时遇到问题import os
def main():
os.system('\\build.rb -p test > out1.txt')
os.system('\\newRelease.rb -l bat > out2.txt')
if __name__ == '__main__':
main()
当我尝试执行代码而不传递'> out1.txt'它被执行并在cmd上显示输出但是当我传递参数'> out1.txt'它不是在out1.txt中写输出。我希望将ruby脚本的输出重定向到txt文件。
答案 0 :(得分:1)
我这样做:
from subprocess import check_output
build = check_output(['\\build.rb', '-p', 'test'])
with open('out1.txt', 'w') as out1:
out1.write(build)
release = check_output(['\\newRelease.rb', '-l', 'bat'])
with open('out2.txt', 'w') as out2:
out2.write(release)