Ruby脚本执行者操作系统()使用python

2024-09-30 22:14:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我在编写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文件。在


Tags: testimportgtbuildtxt脚本osmain
1条回答
网友
1楼 · 发布于 2024-09-30 22:14:14

我会这样做:

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)

相关问题 更多 >