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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -