Created
February 25, 2010 23:34
-
-
Save leepfrog/315179 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Open / create temp file | |
temp_file = Tempfile.new(["myfile",".txt"]) | |
# Write into temp file (this is where the problem is... I believe the myprogram is creating a new file) | |
raise "Problem with my proggy" unless system "/usr/local/bin/myprogram '#{temp_file.path}'" | |
# Read from temp file | |
puts temp_file.read | |
# Close / delete temp file | |
temp_file.close! | |
-- | |
- myprogram inserts data into temp_file | |
- temp_file.read sometimes returns back results... other times it doesn't | |
- i've also attempted to re-open the file: temp_file.reopen(temp_file.path,"r") with the same result | |
my goal is: | |
- have Tempfile create a new and random temp filename inside of <templocation> | |
- have my external process write into this random temp filename | |
- read from this external file | |
- delete the temporary file | |
Unfortunately, I can't pipe or print the information from myprogram. It must be written out to a file... | |
Here's my work-around... which seems a bit messy: | |
# Create temp file, destroy temp file | |
temp_file = Tempfile.new(["myfile",".txt"]) | |
text_file_path = temp_file.path | |
temp_file.close! | |
# Run proggy (which creates temp file) | |
raise "Problem with my proggy" unless system "/usr/local/bin/myprogram '#{text_file_path}'" | |
# Re-open file, Get dataz | |
temp_file.reopen(text_file_path,"r") | |
puts temp_file.read | |
# Close file, clean up tmp | |
temp_file.close | |
File.unlink(text_file_path) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment