Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling external commands with quotes in path via shell on Windows #532

Closed
1 task done
mrpiggi opened this issue May 6, 2020 · 9 comments
Closed
1 task done

Calling external commands with quotes in path via shell on Windows #532

mrpiggi opened this issue May 6, 2020 · 9 comments
Assignees
Labels
Milestone

Comments

@mrpiggi
Copy link

mrpiggi commented May 6, 2020

Hi,
some context first. I am the developer of the LaTeX package svg. I am currently facing the problem that with Inkscape v1.0 the CLI has been changed without backward compatibility. I would like to implement a function to detect the current Inkscape version in order to adapt the automatic call to the respective CLI.

If you need more information feel free to ask for but the main issue is that calling Inkscape with its absolute path in quotes with either \@@input|"'C:/Program Files/Inkscape1/bin/inkscape' -V" or \ShellEscape{"C:/Program Files/Inkscape1/bin/inkscape" -V} does not work with MiKTeX contrary to TeX Live. The latter returns with error message ...quotation error in system command. in the log file of the LaTeX document.

A possible workaround would be to prepend call to the actual call. With this approach \ShellEscape{call "C:/Program Files/Inkscape1/bin/inkscape" -V} gives the expected result while \@@input|call "'C:/Program Files/Inkscape1/bin/inkscape' -V" still does not work. Here is an example which shows all different approaches, the results with TeX Live and MiKTeX are shown afterwards:

\documentclass{minimal}
\usepackage[T1]{fontenc}
\usepackage{shellesc}[2019/11/08]
\begin{document}
\pdftexbanner\endgraf
\ifnum\pdfshellescape=1\relax
  \begingroup%
    \makeatletter
    \@makeother\"%
    \@makeother\|%
    \endlinechar=\m@ne%
    \everyeof{\noexpand}%
    \edef\svg@tempa{\@@input|"inkscape -V" }%
    \meaning\svg@tempa\endgraf%
    \edef\svg@tempa{\@@input|"'C:/Program Files/Inkscape1/bin/inkscape' -V" }%
    \meaning\svg@tempa\endgraf%
    \xdef\svgworkaround{%
      \@@input|"call 'C:/Program Files/Inkscape1/bin/inkscape' -V" %
    }%
  \endgroup%
  \ShellEscape{"inkscape" -V > svg.ink.ver.aux}%
  File content: \input svg.ink.ver.aux \endgraf
  \ShellEscape{echo ??? > svg.ink.ver.aux}%
  \ShellEscape{"C:/Program Files/Inkscape1/bin/inkscape" -V > svg.ink.ver.aux}%
  File content: \input svg.ink.ver.aux \endgraf
  \ShellEscape{echo ??? > svg.ink.ver.aux}%

  \bigskip
  \texttt{call "C:/Program Files/Inkscape1/bin/inkscape" -V}\endgraf
  \meaning\svgworkaround\endgraf%
  \ShellEscape{%
    call "C:/Program Files/Inkscape1/bin/inkscape" -V > svg.ink.ver.aux%
  }%
  File content: \input svg.ink.ver.aux \endgraf
  \ShellEscape{echo ??? > svg.ink.ver.aux}%
\else%
  Enable \texttt{-shell-escape}\endgraf
\fi
Done!
\end{document}

TeXLive.pdf
MiKTeX.pdf

This issue is not urgent for me as there is a workaround but it seems to me that this is a very general one. And it is not only related to the call of Inkscape, just try:

\documentclass{minimal}
\usepackage[T1]{fontenc}
\usepackage{shellesc}[2019/11/08]
\begin{document}
\begingroup%
  \makeatletter
  \endlinechar=44%
%  \endlinechar=\m@ne%
  \everyeof{\noexpand}%
  \edef\@tempa{\@@input|"dir 'C:/Program Files/' /D /B" }%
  \meaning\@tempa\endgraf%
\endgroup
\end{document}
@edocevoli
Copy link
Member

' is not a valid quoting character on Windows, i.e., running

dir 'C:/Program Files/' /D /B

in a command-prompt window does not work. At the moment I am reluctant to adopt the TeX Live hack.

@mrpiggi
Copy link
Author

mrpiggi commented May 7, 2020

So there is (and will be) no way to use paths with spaces for invoking commands on shell-escape (without the usage of call) or pipes at all in MiKTeX?!

I mean \ShellEscape{"C:/Program Files/Inkscape1/bin/inkscape" -V > svg.ink.ver.aux} doesn't work either although it is right regarding syntax on windows. As told, I did find a workaround for my particular problem but how should I escape spaces within pipes?

@edocevoli
Copy link
Member

Indeed

\ShellEscape{"C:/Program Files/Inkscape1/bin/inkscape" -V > svg.ink.ver.aux}

should not give a quotation error.

@edocevoli edocevoli reopened this May 7, 2020
@edocevoli edocevoli self-assigned this May 7, 2020
@edocevoli edocevoli added the bug label May 7, 2020
@edocevoli edocevoli added this to the 2.9.7420 milestone May 7, 2020
edocevoli added a commit that referenced this issue May 7, 2020
@mrpiggi
Copy link
Author

mrpiggi commented May 8, 2020

Thanks a lot!

So there is (and will be) no way to use paths with spaces for invoking commands on [...] pipes at all in MiKTeX?!

\edef\svg@tempa{\@@input|"'C:/Program Files/Inkscape1/bin/inkscape' -V" }%

Do you stick with your decision regarding the single quotes for pipes or do you have an approach/idea how the problem could be solved?

@edocevoli
Copy link
Member

This should work:

\input{|"C:/Program Files/Inkscape1/bin/inkscape" -V}

@edocevoli
Copy link
Member

I see this cannot work because the quotes are eliminated. The TeX Live hack makes sense...

edocevoli added a commit that referenced this issue May 9, 2020
@mrpiggi
Copy link
Author

mrpiggi commented May 9, 2020

Again, thank you a lot

@mrpiggi
Copy link
Author

mrpiggi commented Oct 22, 2020

Another problem occurred: mrpiggi/svg#31

Depending on the format used (pdflatex, lualatex, xelatex) the following MWE gives different results, whereas lualatex und xelatex seem to be faulty:

\listfiles
\documentclass{minimal}
\usepackage[T1]{fontenc}
\begin{document}
\begingroup
  \makeatletter
  \@makeother\|%
  \@makeother\&%
  \catcode\endlinechar=10%
  \everyeof{\noexpand}%
  \edef\parseversion{%
    \xdef\noexpand\pipestdout{\noexpand\@@input|"inkscape\space-V\space2>&1" }%
    \xdef\noexpand\pipenormal{\noexpand\@@input|"inkscape\space-V" }%
  }%
\texttt{\meaning\parseversion}
\parseversion
\endgroup

\texttt{pipestdout}: \pipestdout

\texttt{pipenormal}: \pipenormal
\end{document}

Results for \pipenormal and \pipestdout:

  • pdflatex: ´Inkscape 1.0.1 (3bc2e813f5, 2020-09-07) Pango version: 1.46.1 for both cases
  • lualatex: kscape 1.0.1 (3bc2e813f5, 2020-09-07) Pango version: 1.46.1 [sic] for redirected pipe \pipestdout
  • xelatex: Pango version: 1.46.1 only for both cases

@mrpiggi mrpiggi reopened this Oct 22, 2020
@MiKTeX MiKTeX locked and limited conversation to collaborators Oct 22, 2020
@edocevoli
Copy link
Member

One bug, one issue. Please do not comment/reopen closed issues. You can submit a new issue. Please follow the contribution guidelines when doing so:

  • no links to external web pages
  • step-by-step reproduction instructions

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants