temporary-files

Create a tempfile without opening it in Ruby

ぐ巨炮叔叔 提交于 2019-12-30 06:18:10
问题 Is there a way to create a tempfile, without having it opened? I have to run an executable, redirect it's output to a file, and then read & parse that. Everything created by tempfile is already opened, and this triggers an error , because the file is locked. 回答1: Is using FileUtils.touch acceptable solution? You can touch a file and delete it once you are done with whatever you want. 回答2: You can also use Dir::Tmpname Dir::Tmpname.create('your_application_prefix') { |path| puts path } path

How to create temporary file (0x100) to accelerate application

允我心安 提交于 2019-12-30 01:26:06
问题 I have seen that Windows system use temporary files to increase the performance of some tasks. Those files are marked with the 0x100 attribute when i look at them. I have got the following text from Microsoft: " By using CreateFile() with the FILE_ATTRIBUTE_TEMPORARY flag, you let the system know that the file is likely to be short lived. The temporary file is created as a normal file. The system needs to do a minimal amount of lazy writes to the file system to keep the disk structures

How to send image generated by PIL to browser?

…衆ロ難τιáo~ 提交于 2019-12-28 01:46:06
问题 I'm using flask for my application. I'd like to send an image (dynamically generated by PIL) to client without saving on disk. Any idea how to do this ? 回答1: First, you can save the image to a tempfile and remove the local file (if you have one): from tempfile import NamedTemporaryFile from shutil import copyfileobj from os import remove tempFileObj = NamedTemporaryFile(mode='w+b',suffix='jpg') pilImage = open('/tmp/myfile.jpg','rb') copyfileobj(pilImage,tempFileObj) pilImage.close() remove('

CSHTML file is not compiled anymore

这一生的挚爱 提交于 2019-12-24 14:09:27
问题 While working on an ASP.NET MVC application, I meet the good old "The current source code is different from the version built into App_Web_blahblah.dll" when I'm trying to debug a CSHTML file, whatever I do (deleting Temporary ASP.NET files, PDBs, cleaning and rebuilding, etc). What's more disturbing is that the related CSHTML page isn't compiled anymore. I mean, the application keeps showing an old version of the page, even if this one has changed. There's no errors on this page (the same

create a temporary file with a specified name in java

泄露秘密 提交于 2019-12-23 04:26:31
问题 I have a Byte[] array that i want to put it's content into a temporary file . I have tryied to do it like this try { tempFile = File.createTempFile("tmp", null); FileOutputStream fos = new FileOutputStream(tempFile); fos.write(sCourrier.getBody()); } catch (IOException e) { e.printStackTrace(); } but i want that I specify the filename by myself so not generated by the jvm 回答1: You can directly give the location and file name or You can access local filesystem and find the temp directory

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

╄→гoц情女王★ 提交于 2019-12-22 11:27:38
问题 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 api on Linux and most of them say "Don't use this function" (or similar) in their man page. 回答1: As you can easily see from mktemp(1) source code, it

Why is the WindowsError while deleting the temporary file?

梦想的初衷 提交于 2019-12-22 10:05:48
问题 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:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import tempfile >>> __, filename = tempfile

Is createTempFile thread-safe?

对着背影说爱祢 提交于 2019-12-22 07:01:57
问题 I'm using Java 6. Is it possible that two threads calling createTempFile (of the class java.io.File) get the same temp file? 回答1: Best way to get your answer is to look at the source code. At first there isn't any synchronization in createTempFile, but to generate the temp file name, it is using SecureRandom which is ThreadSafe. Then unless you are really unlucky, your file will always get a different name. On top of that, createTempFile implementation is looping, generating new file name,

How can I automatically create (and remove) a temp directory in a Makefile?

别等时光非礼了梦想. 提交于 2019-12-22 03:52:20
问题 Is it possible to have make create a temp directory before it executes the first target? Maybe using some hack, some additional target etc.? All commands in the Makefile would be able to refer to the automatically created directory as $TMPDIR , and the directory would be automatically removed when the make command ends. 回答1: I seem to recall being able to call make recursively, something along the lines of: all: -mkdir $(TEMPDIR) $(MAKE) $(MLAGS) old_all -rm -rf $(TEMPDIR) old_all: ... rest

Should Dispose() or Finalize() be used to delete temporary files?

南笙酒味 提交于 2019-12-20 10:27:13
问题 I have a class that makes use of temporary files ( Path.GetTempFileName() ) while it is active. I want to make sure these files do not remain on the user's hard drive taking up space after my program is closed. Right now my class has a Close() method which checks if any temporary files used by the class still exist and deletes them. Would it make more sense to put this code in the Dispose() or Finalize() methods instead? 回答1: Better yet would be to create the file with FileOptions