如何将标准输出重定向到 CMD 中的程序?
How can I redirect standard output to a program in CMD?
我在命令提示符中是运行这个:
python -c ""print("""Message from python""")"" | AcceptMessage.exe
但是,这不起作用。我收到消息:
close failed in file object destructor:
sys.excepthook is missing
lost sys.stderr
AcceptMessage.exe
接受一个参数。它所做的只是打印出传递给它的内容。也就是说,如果您通常通过 AcceptArgument.exe argument_here
调用它,输出将是 argument_here
。我已经测试了实际程序,它正常工作,所以这不是问题。
总的来说,我对脚本编写还很陌生,所以非常感谢任何帮助。
像这样尝试(使用 .bat 扩展名保存脚本)
0<0# : ^
'''
@echo off
for /f "tokens=* delims=" %%a in ('python "%~f0" %*') do (
AcceptMessage "%%a"
)
exit /b 0
'''
print("message from python")
或类似的:
@echo off
for /f "tokens=* delims=" %%a in ('"python -c ""print("""Message from python""")"""') do (
acceptMessage "%%a"
)
如果你想运行它直接从命令行:
for /f "tokens=* delims=" %a in ('"python -c ""print("""Message from python""")"""') do @AcceptMessage "%a"
我在命令提示符中是运行这个:
python -c ""print("""Message from python""")"" | AcceptMessage.exe
但是,这不起作用。我收到消息:
close failed in file object destructor:
sys.excepthook is missing
lost sys.stderr
AcceptMessage.exe
接受一个参数。它所做的只是打印出传递给它的内容。也就是说,如果您通常通过 AcceptArgument.exe argument_here
调用它,输出将是 argument_here
。我已经测试了实际程序,它正常工作,所以这不是问题。
总的来说,我对脚本编写还很陌生,所以非常感谢任何帮助。
像这样尝试(使用 .bat 扩展名保存脚本)
0<0# : ^
'''
@echo off
for /f "tokens=* delims=" %%a in ('python "%~f0" %*') do (
AcceptMessage "%%a"
)
exit /b 0
'''
print("message from python")
或类似的:
@echo off
for /f "tokens=* delims=" %%a in ('"python -c ""print("""Message from python""")"""') do (
acceptMessage "%%a"
)
如果你想运行它直接从命令行:
for /f "tokens=* delims=" %a in ('"python -c ""print("""Message from python""")"""') do @AcceptMessage "%a"