[Tutor] how to get variable from an external script or program
shawn bright
nephish at gmail.com
Fri May 29 23:49:13 CEST 2009
kick butt, gents, thanks a lot
sk
On Fri, May 29, 2009 at 4:39 PM, W W <srilyk at gmail.com> wrote:
> On Fri, May 29, 2009 at 4:27 PM, shawn bright <nephish at gmail.com> wrote:
>>
>> Hey all
>>
>> I have a small program that when run from the command line, will
>> return a certain value for an arguement. Like this:
>>
>> > mfetchz 45
>> > 45j
>>
>> so the program is mfetchz and the argument is 45
>>
>> i know i can call the program with os.system("mfetchz 45")
>> but how do i get the return?
>>
>> The OS is linux, if that matters
>
> use subprocess module:
>
> import subprocess
>
> op = subprocess.Popen(['mfetchz', '45'], stdout=subprocess.PIPE)
>
> for line in op.stdout:
> print line
>
>
> HTH,
> Wayne
>
More information about the Tutor
mailing list