Automating an entry for terminal

前端 未结 3 1756
无人及你
无人及你 2021-01-23 19:19

I have a problem which do not really know how to ask. I will try to explain as best as possible.

I have to automate an installation process using a bash script. In the

相关标签:
3条回答
  • 2021-01-23 20:00

    While a particularly difficult script might do some magic to explicitly read from the terminal rather than stdin, odds are you could just pipe to the script using bash pipeline syntax:

    echo yes | python configure.py
    

    or if you prefer, the "single command" version using bash here string syntax:

    python configure.py <<<yes
    

    Lastly, if you need to provide multiple lines of input, probably the easiest approach is bash's heredoc syntax:

    # Remove the single quotes if you need to do variable interpolation in the
    # heredoc; the delimiter ENDOFINPUT is arbitrary, it just has to be used
    # (with or without single quotes) after the `<<` operator, and w/o quotes
    # at the end of the input to terminate the heredoc
    python configure.py <<'ENDOFINPUT'
    yes
    anotherresponse
    andyetanother
    ENDOFINPUT
    
    0 讨论(0)
  • 2021-01-23 20:16

    The PyQt configure script has an option which automatically confirms acceptance of the licence:

    python configure.py --confirm-license
    

    Since there are no other parts of the PyQt installation process that require user input, that should be all you need. For more details, see Installing PyQt4 in the PyQt Docs.

    0 讨论(0)
  • 2021-01-23 20:18

    You can provide input using pip operator (thanks ShadowRanger) Example:

    echo "yes"  | command
    echo "pass" | ssh user@pass
    
    0 讨论(0)
提交回复
热议问题