How to escape /None in \foreach iterator?

You don't want to only escape /None, but also # that's illegal in that context:

\edef\hms{\string#/}% Hash Mark Slash
\foreach \compiler/\ext in {latex/tex,dvips/dvi,ps2pdf -dAutoRotatePages\hms None/ps}
    {\immediate\write18{\compiler\space frames.\ext}}

The variant you mentioned in chat is even better:

\edef\AutoRotateOff{-dAutoRotatePages\string#/None}
\foreach \compiler/\ext in {latex/tex,dvips/dvi,ps2pdf \AutoRotateOff/ps}
    {\immediate\write18{\compiler\space frames.\ext}}

Both exploit the fact that \write fully expands its argument.

Another variant:

\makeatletter
\foreach \compiler/\ext in {latex/tex,dvips/dvi,%
  \@firstofone{ps2pdf -dAutoRotatePages\string#/None}/ps}
    {\immediate\write18{\compiler\space frames.\ext}}
\makeatother

Based on @egreg's answer, the / can be removed from \hms but we need {...} for ps2pdf item as follows.

\edef\hms{\string#}

\foreach \compiler/\ext in {latex/tex,dvips/dvi,{ps2pdf -dAutoRotatePages\hms/None}/ps}{\immediate\write18{\compiler\space temporary.\ext}}

MWE

% this input file name is filename.tex
% compile it with pdflatex -shell-escape filename.tex

\documentclass[preview,border=12pt]{standalone}

\usepackage{filecontents}

\begin{filecontents*}{temporary.tex}
\documentclass[pstricks,border=12pt]{standalone}
\begin{document}
\begin{pspicture}(4,2)
    \rput{90}(2,1){Marienplatz}
\end{pspicture}
\end{document}
\end{filecontents*}


\usepackage{graphicx,pgffor}
\edef\hms{\string#}

\foreach \compiler/\ext in {latex/tex,dvips/dvi,{ps2pdf -dAutoRotatePages\hms/None}/ps}{\immediate\write18{\compiler\space temporary.\ext}}

\begin{document}
\includegraphics{temporary}
\end{document}

More about Windows

In my experience with Windows 7, both -dAutoRotatePages=/None and -dAutoRotatePages#/None work on Windows. Therefore, the simplest solution just needs {...} as follows.

% this input file name is filename.tex
% compile it with pdflatex -shell-escape filename.tex

\documentclass[preview,border=12pt]{standalone}

\usepackage{filecontents}

\begin{filecontents*}{temporary.tex}
\documentclass[pstricks,border=12pt]{standalone}
\begin{document}
\begin{pspicture}(4,2)
    \rput{90}(2,1){Marienplatz}
\end{pspicture}
\end{document}
\end{filecontents*}


\usepackage{graphicx,pgffor}

\foreach \compiler/\ext in {latex/tex,dvips/dvi,{ps2pdf -dAutoRotatePages=/None}/ps}{\immediate\write18{\compiler\space temporary.\ext}}

\begin{document}
\includegraphics{temporary}
\end{document}

Warning

Don't replace \string# with \# as \# will not work (I just tried it).

Tags:

Pgffor