when getting output of system() calls in ruby only part of output is getting stored
when am running some deployment command in ruby script like
system('exam-deploy-all mod.rb >> temp.txt')
only part of output is gett开发者_如何学Pythoning stored in temp.txt
file. I want to store whole output, I think its not storing because the output is very big.
Can anyone tell me how to solve this problem?
I don't think you're losing output because there is too much, I'd guess that some of your output is going to the standard output stream (which you are saving in temp.txt
) and some is going to the standard error (which you are not saving anywhere). You could try this:
system('exam-deploy-all mod.rb > temp.txt 2>errors.txt')
To put the output in temp.txt
and the errors in errors.txt
or one of these:
system('exam-deploy-all mod.rb > temp.txt 2>1')
system('exam-deploy-all mod.rb &> temp.txt')
to put them both in temp.txt
.
Also, doing >> temp.txt
appends the standard output to temp.txt
without overwriting what is already there, > temp.txt
will overwrite temp.txt
with the new output.
All of this assumes that you're using something unixish (such as Linux or OSX) and that you system shell is Bourne-ish (such as bash).
You could also switch to Open3 if you want to handle all the I/O yourself rather than relying on system
and temporary files. Using Open3 is more work but it may be worth it or maybe it isn't.
精彩评论