Results 1 to 3 of 3

Thread: python noob

  1. #1
    Join Date
    Feb 2008
    Beans
    173
    Distro
    Ubuntu 8.04 Hardy Heron

    python noob

    hello im trying to call and pass arguments to an external program in python.

    ex call:
    ./asdf.py ./asdf.rb

    ./asdf.rb is stored in sys.argv[1]

    the problem is that ./asdf.rb is not recieving any of the arguments.
    here is my code.

    Code:
       
    from popen2 import Popen3
    import sys
     
    str = "1 2 3 4" # string of arguments
    call = Popen3('sys.argv[1] %str', True) # argv[1] = ./asdf.rb 
    call_out = call.fromchild.readlines()
    print call_out
    any pointers would be awesome
    thanks
    How do i do ______ in ubuntu?
    Find out here.

  2. #2
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: python noob

    Hi Flynn555. The popen2 module is deprecated.
    I believe you are encouraged to use the subprocess modules instead.

    Maybe this would work for you?

    PHP Code:
    #!/usr/bin/env python
    from subprocess import Popen,PIPE
    import sys
     
    str 
    "1 2 3 4" # string of arguments
    cmd='%s %s'%(sys.argv[1],str)
    print(
    cmd)
    call=Popen(cmdshell=Truestdout=PIPE# argv[1] = ./asdf.rb 
    call_out=call.communicate()[0]
    print 
    call_out 

    See http://docs.python.org/library/subpr...ule-subprocess
    and http://blog.doughellmann.com/2007/07...ubprocess.html.

  3. #3
    Join Date
    Feb 2008
    Beans
    173
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: python noob

    Quote Originally Posted by unutbu View Post
    Hi Flynn555. The popen2 module is deprecated.
    I believe you are encouraged to use the subprocess modules instead.

    Maybe this would work for you?

    PHP Code:
    #!/usr/bin/env python
    from subprocess import Popen,PIPE
    import sys
     
    str 
    "1 2 3 4" # string of arguments
    cmd='%s %s'%(sys.argv[1],str)
    print(
    cmd)
    call=Popen(cmdshell=Truestdout=PIPE# argv[1] = ./asdf.rb 
    call_out=call.communicate()[0]
    print 
    call_out 

    See http://docs.python.org/library/subpr...ule-subprocess
    and http://blog.doughellmann.com/2007/07...ubprocess.html.

    hey, thanks!
    How do i do ______ in ubuntu?
    Find out here.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •