0
我想的文本文件饋送到C程序,使用bash我可以做./prog <file
,你會怎麼做在python一樣嗎?如何在python中執行輸入重定向,如bash>?
我想的文本文件饋送到C程序,使用bash我可以做./prog <file
,你會怎麼做在python一樣嗎?如何在python中執行輸入重定向,如bash>?
你可以做到這一點通過subprocess.check_call
:
import subprocess
subprocess.check_call(["prog"], stdin=open("/path/to/file"))
你能不能解釋一下?你想把輸入饋入外部程序嗎? –
@SergeiLebedev是的我想喂一個文本文件到一個C程序'prog',所以我可以用'getchar()'來抓它。在bash中我只是'$ ./prog
ChiseledAbs