shell - python: string as stdin to subcommand -
i have python script in need invoke shell command. shell command can accept input either file or stdin.
in script, input stored in variable. proper way invoke command? if matters, shell command produces no output.
i know write variable's content file , invoke command file argument seems inelegant. surely, there's better way.
can tell me is? thanks.
you can use subprocess module.
import subprocess process = subprocess.popen(["mycommand", "with", "arguments"], stdin=subprocess.pipe) process.communicate("my text")
Comments
Post a Comment