Re: how to run shell command like "<<EOT .... EOT"

Discussion in 'Python' started by Dennis Lee Bieber, Oct 8, 2012.

  1. On Mon, 08 Oct 2012 08:53:46 +0800, ??? <> declaimed
    the following in gmane.comp.python.general:


    > fop = os.popen ("sfdisk -uM %s <<EOT\n,%d,83\n,,83\nEOT\n" % (target, fps))
    >
    > But when I run it with subprocess.Popen (), it doesn't work as os.popen
    > even use the code as:
    >
    > command = ["sfdisk", "-uM", target ]
    > instructions = """


    Try with a \ at the end of the above line. The triple quoted string
    retains ALL line endings, including the one from the quotes down to the
    following line.

    > ,1000,83
    > ,,83
    > """
    >


    >>> INSTRUCTIONS = """

    .... ,1000,83
    .... ,,83
    .... """
    >>>
    >>> print repr(INSTRUCTIONS)

    '\n,1000,83\n,,83\n'
    >>> for c,ln in enumerate(INSTRUCTIONS.split("\n")):

    .... print c, '"%s"' % ln
    ....
    0 ""
    1 ",1000,83"
    2 ",,83"
    3 ""

    vs

    >>> INSTRUCTIONS = """\

    .... ,1000,83
    .... ,,83
    .... """
    >>> print repr(INSTRUCTIONS)

    ',1000,83\n,,83\n'
    >>> for c,ln in enumerate(INSTRUCTIONS.split("\n")):

    .... print c, '"%s"' % ln
    ....
    0 ",1000,83"
    1 ",,83"
    2 ""
    >>>

    --
    Wulfraed Dennis Lee Bieber AF6VN
    HTTP://wlfraed.home.netcom.com/
     
    Dennis Lee Bieber, Oct 8, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    5,733
    Jonathan Bromley
    Feb 18, 2005
  2. Replies:
    4
    Views:
    1,717
    Terry Hancock
    Apr 23, 2005
  3. Sonu
    Replies:
    2
    Views:
    381
    Alex Popescu
    Aug 5, 2007
  4. Bill

    More like a shell command.

    Bill, Aug 6, 2008, in forum: Python
    Replies:
    4
    Views:
    300
    castironpi
    Aug 6, 2008
  5. Kushal Kumaran
    Replies:
    0
    Views:
    188
    Kushal Kumaran
    Sep 29, 2012
Loading...

Share This Page