In my tex file I want to call plink (command line application for PuTTY) in order to execute a remote command and read the output. When I do this I get an error 'Unable to read from standard input: The handle is invalid'


   Calling plink from within LaTeX...

   \immediate\write18{plink -load my_session echo remote_response}


I think this error is output by plink, not LaTeX, and I'm not the first to encounter this problem (link1: http://jamesmcdonald.id.au/it-tips/plinkexe-unable-to-read-from-standard-input-the-handle-is-invalid/comment-page-1#comment-115264, link2: http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/win-plink-stdin-handle-invalid.html)

The solution is appearently to 'redirect STDIN and STDOUT', and though I'm vaguely aware what it means, I'm not sure how to do this in LaTeX. Any ideas?

  • have you tried with smt like \immediate\write18{plink -load my_session echo remote_response > bla.out 2> bla.err < bla.in} ? – Bordaigorl Oct 1 '14 at 11:11
  • I haven't; when I try to do this for only the outputs the same error message ('Unable to read from standard input: The handle is invalid') is printed to bla.err. When I include the input file, the latex compiler hangs. I Don't think this is supposed to happen? – Dirk van den Bekerom Oct 1 '14 at 11:26
  • Have you tried creating an empty file bla.in? Is plink usually requiring some user input? – Bordaigorl Oct 1 '14 at 13:15
  • Can you try adding the -batch option? – Bordaigorl Oct 1 '14 at 13:16
  • I got a workaround by using echo and pipe the output to cmd, but I can imagine there are prettier solutions. At least it works like this: \immediate\write18{echo plink -load my_session echo remote_response | cmd} – Dirk van den Bekerom Oct 1 '14 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.