[Baypiggies] how can I change the input parameter in my executable while calling from either os.system or os.popen calls?

Shannon -jj Behrens jjinux at gmail.com
Thu Aug 21 02:59:02 CEST 2008


On Wed, Aug 20, 2008 at 5:53 PM, David Elsen <elsen.david08 at gmail.com> wrote:
> Hello all,
>
> I have defined a class as following:
>
> class reg:
>      def __init__ (self, offset):
>                 self.offset = offset
>
>      def reg_read(self, offset):
>              print 'Read the reg conten specified by offset'
>              import os
>              read_cmd = './testtool  0x50'
>              read_content = os.popen(read_cmd).read()
>
> reg1 = reg (0x50)
>
> reg1.reg_read(0x50)
>
>
> The above code calls my c executable with offset 0x50 and gives me the
> content of 0x50 offset.
>
> I wanted to change the above code as following:
>
> class reg:
>      def __init__ (self, offset):
>                 self.offset = offset
>
>      def reg_read(self, offset):
>              print 'Read the reg conten specified by offset'
>              import os
>              read_cmd = './testtool  offset'
>              read_content = os.popen(read_cmd).read()
>
> reg1 = reg (0x50)
>
> reg1.reg_read(0x50)
>
> Basically I wanted to pass the offset as input parameter to my executable
> "testtool" and run the testtool for offset.
>
> But looks like it does not allow me to change my offset.
>
> Is there a way to do this in python?
>
> Thanks in advance,
> David

Have a peek at http://docs.python.org/lib/module-subprocess.html.
This has the additional benefit that you can pass a list of args
instead of a single string.

-jj

-- 
Don't you wish you had a really clever sig like mine?
http://jjinux.blogspot.com/


More information about the Baypiggies mailing list