user3012554
user3012554

Reputation: 33

Ruby script executed by os.system() using python

I am facing issue while writing output of ruby script executed by os.system()

import os
def main():
    os.system('\\build.rb -p test > out1.txt')
    os.system('\\newRelease.rb -l bat > out2.txt')

if __name__ == '__main__':
    main()

When I try to execute the code without passing the '> out1.txt' it gets executed and shows output on cmd but when I pass the parameter ' > out1.txt' it is not writing output in out1.txt. I want the output of the ruby script to be redirected to the txt file.

Upvotes: 3

Views: 467

Answers (1)

John Zwinck
John Zwinck

Reputation: 249273

I'd do it this way:

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)

Upvotes: 1

Related Questions