0

https://stackoverflow.com/questions/3252957/how-to-execute-shell-script-from-latex

Is there any way to execute a program and have it directly insert it's stdout in to the tex stream without having to output to a temp file and then input that file? [I've tried some of the code in the link but it does not work, specifically the 2019 update code).

If not, is there an easy way to generate a random file name that won't collide and then input it and delete it? Ideally though this is not the method I'd like.

I can use the write18 method and input but it is not desirable.

  • 3
    Possible duplicate of Specify file name shell access via @@input. I think that \GetShellOutput defined in the answer does exactly what you want. It can easily be modified to take a parameter that defines what is to be executed. – Peter Grill Sep 26 '19 at 00:33
  • @PeterGrill none of these seem to do anything that I want, they all use an external temp file which is explicitly what I said I did not want. –  Sep 26 '19 at 13:17
  • Perhaps I am missing something, but I don't see a temp file used in the \GetShellOutput macro that is linked in my earlier comment. The two files A.txt and B.txt are not temp files -- they are there only because the command I want to execute is intended to extract info from a file, and those two are the test files. – Peter Grill Sep 26 '19 at 15:58
  • @PeterGrill When I run the code I get l.30 \GetShellOutput Please type another input file name:. e.g., I simply modified the code: \@@input|"head -1 \FBFileNameWithPath | grep '^XY:'" }}% to \@@input|"dir" }}%. I've tried with other things such as the exe I want to run with the full path and it gives the same error. So maybe it doesn't use a temp file but I cannot get it to work. –  Sep 26 '19 at 16:35
  • I just tested with \@@input|"pwd" } on MacOS and seems to work fine. Are you using the -shell-escape option to pdflatex? If that is not the problem, I suggest you post a new question and include a compile MWE including \documentclass and the appropriate packages that reproduces the problem that you are having. – Peter Grill Sep 26 '19 at 18:35
  • @PeterGrill I am on windows and yes I'm using shell-escape. The code is EXACTLY from that link. I just copied and pasted and changed the command. A MWE would be useless, just go to that page and copy and paste but change the command to something like dir. –  Sep 26 '19 at 18:44
  • @PeterGrill even if I simply do \makeatletter \@@input"dir" \makeatother it fails with the same error. (with or without the |) –  Sep 26 '19 at 18:45
  • Sorry, not sure how to help you any further. Thus, my suggestion to post a new question. Also, I disagree that a MWE would be useless. Why bother describing the edit when you can just make the edit that you are describing and post that in the question so that anyone trying to help you does not have to bother with it. – Peter Grill Sep 26 '19 at 18:49
  • @PeterGrill It seems it has to be a file to open. I had to copy an exe in to the main dir and absolute paths do not work. dir does not work because there is no dir in the folder. If I drop the | and copy the file and use it then the errors are: Text line contains an invalid character so it at least does something different. Using | fails though. –  Sep 26 '19 at 18:50
  • @PeterGrill I don't see why I should simply copy and paste code that anyone can go to a link and do. If it works for you then it is a deeper problem in that even if I post a MWE it will work for you and not work for me so it solves nothing ultimately. MWE do not solve every problem and many times they are not needed. –  Sep 26 '19 at 18:52
  • @PeterGrill For example, I had to figure it out myself... realizing that absolute paths do not work for some bizare reason and the exe must exist in the directory. Also that | was breaking the code. Now I get errors like Illegal parameter number in definition of \TempResult and Text line contains an invalid character. –  Sep 26 '19 at 18:53
  • @PeterGrill I think @@input is not reading anything but trying to load the file ;/ That is why I get errors. It's trying to read the exe as a text file and has nothing to do with executing... just like \input. Maybe \@@input|".." is suppose to execute the command but in my case it says it can't find the file |.... This is on windows. Maybe it works on linux correctly but not so much on windows. I will just use a temp file, at least it works. –  Sep 26 '19 at 19:01

0 Answers0