To run a visual basic script named readCSV.vbs in/before/during latex compilation, I have the following MWE:

% line3:
%\immediate\write18{readCSV.vbs} %Works If you put it next to main
% line5:
\immediate\write18{"/CsvTasks/readCSV.vbs"} % Does not work




If I: 1. Put the readCSV.vbs directly in the same folder as main.txt 2. Open cmd and browse to the directory, e.g. E:/folder path with a space in it/project folder/ that contains the readCSV.vbs 3. Execute command: pdflatex --enable-write18 -interaction=nonstopmode main.tex

It works fine with the line 3 uncommented, meaning it compiles and runs the script directly in the same folder as Main.tex.

However when I run it with line 5, commenting line 3, it does not work. (All below commands are executed from directory: E:/folder path with a space in it/project folder/ which contains the main.tex.)

The error message is:

(e:/texlive/2018/texmf-dist/tex/latex/base/size10.clo))The system cannot find the path specified.

Edits in response to the comments:

The option:



e:/texlive/2018/texmf-dist/tex/latex/base/size10.clo))'CsvTasks' is not recognized as an internal or external command, operable program or batch file.

And the option:



(e:/texlive/2018/texmf-dist/tex/latex/base/size10.clo))'.' is not recognized as an internal or external command, operable program or batch file.

And the option:

\immediate\write18{"E:/folder path with a space in it/project folder/CsvTasks/readCSV.vbs"}

Works. However, I intend to make it runnable on different pc's, which is why I am either looking for:

  • A functioning \write18 command that only requires the subfolder
  • A way to get the absolute path of main.tex into the latex so that I can paste the subfolder behind it.

For completeness: I am running this on a windows 10 pc with Texmaker.


How can I run the readCSV.vbs from latex with the \write18command from sub/relative directory /CsvTasks/readCSV.vbs?

  • 2
    you have /CsvTasks/readCSV.vbs which means the file is at the root of the filesystem so c:\CsvTasks\readCSV.vbs if that is not where the file is then you are perhaps looking for CsvTasks/readCSV.vbs or equivalently ./CsvTasks/readCSV.vbs which would be a file in the CsvTasks folder of the working directory – David Carlisle Sep 12 '19 at 19:44
  • @DavidCarlisle Thank you for your suggestions, I have tried them both, though I have not yet managed to get them working. Indeed the absolute path to the relative/sub folder does work. So I will be looking for a way to get the directory of the main as a dynamic function, so that it will also work in other scenarios. Ofcourse a relative path would be a more elegant solution. – a.t. Sep 12 '19 at 20:44
  • Oh sorry vbs is not an executable it's a visual basic script so you need the first argument to be the script runtime so something like \write18{cscript CsvTasks\string\readCSV.vbs} – David Carlisle Sep 13 '19 at 8:07
  • 1
    but as you said the absolute path worked perhaps I am wrong that you need cscript explicitly. Note that the paths are relative to the directory from which you run tex, nit from the file. If you start with pdflatex mydocument that is the same thing, but if you started via pdflatex /documents/myfile.tex then the working directory for the executable may be the root or your desktop or whatever, depending on how you set things up. – David Carlisle Sep 13 '19 at 8:10
  • Thank you for your elaboration, that the relative path is relative to the "cmd/compile-invoking"-command does indeed complicate or disable my intended goal with relative folder. However, it does not explain why it does not work so far, since I indeed invoked it from the folder that contains the main.tex in cmd. – a.t. Sep 13 '19 at 8:28

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.