Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 327
user3012554 Avatar asked Mar 16 '26 14:03

user3012554


1 Answers

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)
like image 142
John Zwinck Avatar answered Mar 19 '26 04:03

John Zwinck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!