title: Using io.tmpfile() with shell command, ran via io.popen, in Lua?
body: <p>I'm using Lua in Scite on Windows, but hopefully this is a general Lua question.</p>
  <p>Let's say I want to write a temporary string content to a temporary file in Lua - which I want to be eventually read by another program, - and I tried using <code>io.tmpfile()</code>:</p>
  <pre class="lang-lua prettyprint-override"><code>mytmpfile = assert( io.tmpfile() )
  mytmpfile:write( MYTMPTEXT )
  mytmpfile:seek(&quot;set&quot;, 0) -- back to start
  print(&quot;mytmpfile&quot; .. mytmpfile .. &quot;&lt;&lt;&lt;&quot;)
  mytmpfile:close()
  </code></pre>
  <p>I like <code>io.tmpfile()</code> because it is noted in <a href="https://www.lua.org/pil/21.3.html" rel="nofollow noreferrer">https://www.lua.org/pil/21.3.html</a> :</p>
  <blockquote>
  <p>The tmpfile function returns a handle for a temporary file, open in read/write mode. That file is automatically removed (deleted) when your program ends.</p>
  </blockquote>
  <p>However, when I try to print <code>mytmpfile</code>, I get:</p>
  <pre class="lang-none prettyprint-override"><code>C:\Users\ME/sciteLuaFunctions.lua:956: attempt to concatenate a FILE* value (global 'mytmpfile')
  &gt;Lua: error occurred while processing command
  </code></pre>
  <p>I got the explanation for that here <a href="http://lua-users.org/lists/lua-l/2010-10/msg00827.html" rel="nofollow noreferrer">Re: path for io.tmpfile() ?</a>:</p>
  <blockquote>
  <blockquote>
  <blockquote>
  <p>how do I get the path used to generate the temp file created by io.tmpfile()</p>
  </blockquote>
  <p>You can't. The whole point of tmpfile is to give you a file handle without
  giving you the file name to avoid race conditions.</p>
  </blockquote>
  <p>And indeed, on some OSes, the file has no name.</p>
  </blockquote>
  <p>So, it will not be possible for me to use the filename of the tmpfile in a command line that should be ran by the OS, as in:</p>
  <pre class="lang-lua prettyprint-override"><code>f = io.popen(&quot;python myprog.py &quot; .. mytmpfile)
  </code></pre>
  <p>So my questions are:</p>
  <ul>
  <li>Would it be somehow possible to specify this tmpfile file handle as the input argument for the externally ran program/script, say in <code>io.popen</code> - instead of using the (non-existing) tmpfile filename?</li>
  <li>If above is not possible, what is the next best option (in terms of not having to maintain it, i.e. not having to remember to delete the file) for opening a temporary file in Lua?</li>
  </ul>