5
$\begingroup$

I have Windows 10 Professional x64 with WSL2 installed. I've also installed Ubuntu 20.04 LTS from Microsoft Store.

I can type ubuntu2004 in the CMD and get access to Linux utils installed under Ubuntu. For example, I've installed the poppler-utils and now have pdfunite:

screenshot

My disk C:\ is already mounted in the Ubuntu filesystem as /mnt/c and I have full access to it from my Ubuntu:

screenshot2

Suppose I have copied (under Windows) two PDF files into this directory, say 1.pdf and 2.pdf:

screenshot3

And I wish to combine them using pdfunite from Ubuntu, but I want to perform this programmatically from Mathematica, without using the terminal interface. Under the terminal, it would be sufficient just to type:

pdfunite 1.pdf 2.pdf combined.pdf

But how can I do this from Mathematica using perhaps such commands as RunProcess or ExternalEvaluate?

P.S. pdfunite is just an example. Actually I wish to understand how I can use any Ubuntu command-line utility from Mathematica installed on Windows.

$\endgroup$
3
  • $\begingroup$ One option I've heard works quite well is to just use the linux version of Mathematica instead of the Windows version, but I have no first-hand experience with that. If that is too drastic, maybe this will help? $\endgroup$
    – Jason B.
    Jan 12, 2022 at 15:20
  • $\begingroup$ If that link is relevant I would try RunProcess[{"wsl", "pdfunite", "1.pdf", "2.pdf", "combined.pdf"}], assuming the PDFs are on the path and all. $\endgroup$
    – Jason B.
    Jan 12, 2022 at 15:27
  • $\begingroup$ @JasonB. Thank you, I've found that in the Windows terminal ubuntu2004 run pdfunite 1.pdf 2.pdf combined.pdf works! $\endgroup$ Jan 12, 2022 at 15:33

1 Answer 1

3
$\begingroup$

Thanks to the answer linked by Jason B., after experimenting a bit I've found that it is as easy as follows:

SetDirectory["C:\\Mathematica_work"];
RunProcess[{"ubuntu2004", "run", "pdfunite", "1.pdf", "2.pdf", "combined.pdf"}]
<|"ExitCode" -> 0, "StandardOutput" -> "", "StandardError" -> ""|>

Now we got the desired combined.pdf:

FileNames[]
{"1.pdf", "2.pdf", "combined.pdf"}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.