如何重定向默认程序输出?

2024-04-28 21:11:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试通过管道将python脚本的输出进行pygmentize。你知道吗

在注册表中,我将其设置为:

"C:\Anaconda\python.exe" "%1"%* | pygmentize

不工作(根本没有管道),怎么了?你知道吗


Tags: 脚本管道注册表anacondaexepygmentize
1条回答
网友
1楼 · 发布于 2024-04-28 21:11:27

您可以使用powershell进行此操作

C:\ PowerShell -Command " python [yourprogram.py] | pygmentize -l py3t"

-Command

Executes the specified commands (and any parameters) as though they were typed at the Windows PowerShell command prompt, and then exits, unless the NoExit parameter is specified. Essentially, any text after -Command is sent as a single command line to PowerShell (this is different from how -File handles parameters sent to a script).

The value of Command can be "-", a string. or a script block. If the value of Command is "-", the command text is read from standard input. Script blocks must be enclosed in braces ({}). You can specify a script block only when running PowerShell.exe in Windows PowerShell. The results of the script are returned to the parent shell as deserialized XML objects, not live objects.

If the value of Command is a string, Command must be the last parameter in the command, because any characters typed after the command are interpreted as the command arguments. To write a string that runs a Windows PowerShell command, use the format:

"& {<command>}"

where the quotation marks indicate a string and the invoke operator (&) causes the command to be executed.

上述Command文档可以在here中找到

相关问题 更多 >