如何在 Postscript 中将变量打印到标准输出

How can I print a variable to stdout in Postscript

我可以像这样将字符串打印到标准输出:

(%stderr) (w) file dup (a_string\n) writestring closefile

但是我好像做不到

(a_string)
(%stderr) (w) file dup pop writestring closefile

或类似的东西。

有什么帮助吗?

我认为您需要将 pop 更改为 exch:

(a_string)
(%stderr) (w) file dup exch writestring closefile

首先,您要写入 stderr。要写入标准输出,请使用 (%stdout) 作为特殊设备。

但是,如果您要写入标准输出,只需使用 =print(如果您不需要换行符)。

实际使用writestringclosefile,先放文件,然后dup然后把字符串压栈.

(%stderr) (w) file dup  % f f
(string)                % f f s
writestring             % f
closefile               %

如果字符串已经在堆栈中,您可以稍微调整一下以正确的顺序排列各个部分。

(string)                % s
(%stderr)(w)file        % s f
exch                    % f s
1 index                 % f s f
exch                    % f f s
writestring
closefile

exch 1 index exch也可以写成dup 3 2 roll.

此外,永远不需要关闭标准输入、标准输出或标准错误。所以你可以丢掉那部分。

(%stderr)(w)file (string) writestring