How to send a var to stdin of an external software
Benjamin Watine
watine at cines.fr
Thu Mar 13 10:44:26 EDT 2008
Marko Rauhamaa a écrit :
> Benjamin Watine <watine at cines.fr>:
>
>> How can I do this ? I would like a function like that :
>>
>> theFunction ('cat -', stdin=myVar)
>>
>> Another related question : Is there's a limitation of var size ? I
>> would have var up to 10 MB.
>
> import subprocess
> myVar = '*' * 10000000
> cat = subprocess.Popen('cat',shell = True,stdin = subprocess.PIPE)
> cat.stdin.write(myVar)
> cat.stdin.close()
> cat.wait()
>
>
> Marko
>
Thank you Marko, it's exactly what I need.
And if somebody need it : to get the stdout in a var (myNewVar), not in
the shell :
cat = subprocess.Popen('cat', shell = True, stdin = subprocess.PIPE,
stdout=subprocess.PIPE)
cat.stdin.write(myVar)
cat.stdin.close()
cat.wait()
myNewVar = cat.stdout.read()
Is it correct ?
Ben
More information about the Python-list
mailing list