How can I do this with python ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Xiao Jianfeng

    #1

    How can I do this with python ?

    Dear all,

    In a shell script, I can run a command which need interactive input like
    this,

    #!/bin/sh

    A_Command<<-EOF
    a
    b
    c
    EOF

    But, how can I do this with python ?

    Thanks in advance.
  • Tim N. van der Leeuw

    #2
    Re: How can I do this with python ?

    Your question is insufficiently clear for me to answer.

    Do you want to know how to read from standard-input in a Python
    program?

    Do you want to know how to start an external program from Python, and
    then connect something to that programs standard input?

    Do you want to know something else?

    Please specify!

    Cheers,

    --Tim

    Comment

    • Xiao Jianfeng

      #3
      Re: How can I do this with python ?

      Tim N. van der Leeuw wrote:[color=blue]
      > Your question is insufficiently clear for me to answer.
      >
      > Do you want to know how to read from standard-input in a Python
      > program?
      >
      > Do you want to know how to start an external program from Python, and
      > then connect something to that programs standard input?
      >
      > Do you want to know something else?
      >
      > Please specify!
      >
      > Cheers,
      >
      > --Tim
      >
      >[/color]
      Thanks.

      For example, I can call vim and do something like this in a shell script,

      #!/bin/sh

      vim a.file<<-EOF
      :some_vim_comma nd
      :some_vim_comma nd
      :w
      :q
      EOF

      I want to know how to call vim and to the same thing with python.

      Regrads,

      Comment

      • Philippe Martin

        #4
        Re: How can I do this with python ?

        Xiao Jianfeng wrote:
        [color=blue]
        > Tim N. van der Leeuw wrote:[color=green]
        >> Your question is insufficiently clear for me to answer.
        >>
        >> Do you want to know how to read from standard-input in a Python
        >> program?
        >>
        >> Do you want to know how to start an external program from Python, and
        >> then connect something to that programs standard input?
        >>
        >> Do you want to know something else?
        >>
        >> Please specify!
        >>
        >> Cheers,
        >>
        >> --Tim
        >>
        >>[/color]
        > Thanks.
        >
        > For example, I can call vim and do something like this in a shell script,
        >
        > #!/bin/sh
        >
        > vim a.file<<-EOF
        > :some_vim_comma nd
        > :some_vim_comma nd
        > :w
        > :q
        > EOF
        >
        > I want to know how to call vim and to the same thing with python.
        >
        > Regrads,[/color]

        hi,

        os.popen should do that.

        Philippe


        Comment

        • Harold Fellermann

          #5
          Re: How can I do this with python ?

          Better go for the subprocess module. It is supposed to replace os.popen
          and has a much nicer interface.

          - harold -

          Comment

          Working...