tempfile

How do I persist to disk a temporary file using Python?

I am attempting to use the 'tempfile' module for manipulating and creating text files. Once the file is ready I want to save it to disk. I thought it would be as simple as using 'shutil.copy'. However, I get a 'permission denied' IOError: >>> import tempfile, shutil >>> f = tempfile.TemporaryFile(mode ='w+t') >>> f.write('foo') >>> shut...

How can I create a temporary file for writing in C++ on a Linux platform?

In C++, on Linux, how can I write a function to return a temporary filename that I can then open for writing? The filename should be as unique as possible, so that another process using the same function won't get the same name. ...

Python - How do I convert "an OS-level handle to an open file" to a file object?

tempfile.mkstemp() returns "a tuple containing an OS-level handle to an open file (as would be returned by os.open()) and the absolute pathname of that file, in that order." How do I convert that OS-level handle to a file object? The documentation for os.open() states: To wrap a file descriptor in a "file object", use fdopen(). ...

How do I save a NamedTemporaryFile into a model FileField in Django?

I created a NamedTemporaryFile, added some content in it and now I want to save it into a model FileField. The problem is that I get a SuspiciousOperation because the tmp directory is not within the FileSystemStorage directory. What's the proper way to do this? ...

How do I automatically delete tempfiles in c#?

Hello all. What are a good way to ensure that a tempfile is deleted if my application closes or crashes? Ideally I would like to obtain a tempfile, use it and then forget about it. Right now I keep a list of my tempfiles and delete them with an eventhandler that triggers on Application.ApplicationExit. Is there a better way? ...

On Linux, is the command-line program mktemp less safe than the C-function mkstemp?

Both operations create an empty file and return the filename but mkstemp leaves the file open in exclusive mode and gives you the handle. Is there a safety benefit to the C-function? Does this imply that there is a safety hole in the command-line version? As an aside, it is interesting that there are several related functions in the C...

In Python, how do I make a temp file that persists until the next run?

I need to create a folder that I use only once, but need to have it exist until the next run. It seems like I should be using the tmp_file module in the standard library, but I'm not sure how to get the behavior that I want. Currently, I'm doing the following to create the directory: randName = "temp" + str(random.randint(1000, 999...

Removing created temp files in unexpected bash exit

I am creating temporary files from a bash script. I am deleting them at the end of the processing, but since the script is running for quite a long time, if I kill it or simply CTRL-C during the run, the temp files are not deleted. Is there a way I can catch those events and clean-up the files before the execution ends? Also, is there s...

How to delete the temporary files automatically in ruby-rails?

Hi, My Rails app has to process and generate PDF XFA files and send to the user/browser. Its working fine. But the issue is that before sending the file to the user, it creates 2 files in the rails tmp directory. If 10 requests come to the pdf_controller, the number of the temp files in the tmp directory will double and it will eat up ...

Windows programming application and writing temporary files

I am writing an app that may have in its memory quite a bit of data. I dont want to write the data to disk ad hoc because there may be more data to write, I could append the data, but I dont want to run into any file corruption issues. Are there any good tutorials or trusted methods describing how a windows program typically makes use ...

Is there an easy way to use a python tempfile in a shelve (and make sure it cleans itself up)?

Basically, I want an infinite size (more accurately, hard-drive rather than memory bound) dict in a python program I'm writing. It seems like the tempfile and shelve modules are naturally suited for this, however, I can't see how to use them together in a safe manner. I want the tempfile to be deleted when the shelve is GCed (or at guara...

How do I force the browser to get an updated PDF file generated from an SSRS report?

I have a web page that downloads a pdf version of an ssrs report through a link. However when I make changes to the data, the browser pulls up the same pdf file as before without the updated information (the pdf file stored in the temp folder). If I then go to another browser and download the PDF I get the new version, but the other brow...

JRuby - Tempfile.rb

Hey, Does anyone know how tempfile.rb is handled in JRuby. It is in Ruby but not in JRuby. Anyone got anyideas? Cheers Eef ...

Why is the WindowsError while deleting the temporary file?

I have created a temporary file. Added some data to the file created. Saved it and then trying to delete it. But I am getting WindowsError. I have closed the file after editing it. How do I check which other process is accessing the file. C:\Documents and Settings\Administrator>python Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:...

Python tempfile module and threads aren't playing nice; what am I doing wrong?

I'm having an interesting problem with threads and the tempfile module in Python. Something doesn't appear to be getting cleaned up until the threads exit, and I'm running against an open file limit. (This is on OS X 10.5.8, Python 2.5.1.) Yet if I sort of replicate what the tempfile module is doing (not all the security checks, but jus...

CGI -- Temporary files

Hello! I'm developing a little CGI application (in C, with CGIC, http://www.boutell.com/cgic/). My application needs to create a temporary file (the user upload an images, it is saved, modified in various ways, and then shown back to the user). What precautions should I take while creating temporary files? The modified image is provide...

php: Grabbing stdout output data from cli tools?

Is it possible to grab the stdout output data from command line tools in php? Example: I want to upload a dynamically server-created mix of audio files to the client. The SOX tool lets me mix the input mp3s and send the result to stdout pipe. Could I grab this mix and instantly upload it, without the need of first saving it as a tempf...

XML Retrieval - through function calls or temp files?

We are creating an application for a client's website. The website will make a function call to our application to generate XML data. The web service then must retrieve this data. Would it be best for us to return the XML data as a part of our function, or would we be better to create temp files? If creating temp files is the better ...

What folder does Path::GetTempFileName Method save to?

I need to get the temp file to see what happened because the actual file is never output. However, I can't seem to find where the temp file is created. I need to find this out without writing code or building the application because there are too many dependencies scattered all over the place. I would not be able to deploy a debug versi...

Temp Filename on specific partition?

I know about Path.GetTempFileName() and how to get the temp folder (usually its on your C drive) But how do i get a temp filename on a specific partition? i think as a workaround i'll do something like targetBaseDir/temp.tmp and then File.Move when its complete. ...