I have created temporary named files, with the tempfile libraries NamedTemporaryFile method. I have written to them flushed the buffers, and I have not closed them (or else they might go away)
I am trying to use the subprocess module to call some shell commands using these generated files.
subprocess.call('cat %s' % f.name) always fails saying that the named temporary file does not exist.
os.path.exists(f.name) always returns true.
I can run the cat command on the file directly from the shell.
Is there some reason the subprocess module will not work with temporary files?
Is there any way to make it work?
Thanks in advance.
Why don't you make your NamedTemporaryFiles with the optional parameter delete=False? That way you can safely close them knowing they won't disappear, use them normally afterwards, and explicitly unlink them when you're done. This way everything will work cross-platform, too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With