How to handle shell prompt in maven

喜你入骨 提交于 2019-12-11 04:23:11

问题


I have a pom.xml file that executes a shell script, and the shell script has the prompt

"Enter 'YES' to have this script continue:"

How do I tell maven 1)Parse the prompt, 2)Enter YES when it sees the prompt?

Or at the least, an answer to the second question above?

Thanks.


回答1:


I had a similar problem. One of my plugins was designed to display some information to user and proceed only after confirmation. When I had to use it on our CI build server, I ended up with this:

echo 'y' | mvn release:branch ...

I assume that you could either go with this approach (if it works for you), or use gmaven plugin to execute Groovy code before the execution of your shell script that would write needed string to system input.




回答2:


You're using an interactive script in non-interactive mode. The script should have a parameter (ie. --non-interactive, or -y / -n, etc.) which disable the prompt and force the answer.




回答3:


Setup script run as yes | ./script in pom.xml




回答4:


I ended up using https://bitbucket.org/atlassian/bash-maven-plugin and had this in my pom.xml file

    <plugin>
        <groupId>com.atlassian.maven.plugins</groupId>
        <artifactId>bash-maven-plugin</artifactId>
        <version>1.0-SNAPSHOT</version>
        <executions>
            <execution>
                <id>execute-shell</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>run</goal>
                </goals>
                <configuration>
                    <script>./build_dm.sh --accept-warning</script>
                </configuration>
            </execution>
        </executions>
    </plugin>



回答5:


You could use Expect, writing a wrapper script which, in turn, calls the interactive script.

To install it on Ubuntu:

sudo apt-get install expect

This script should work:

#!/usr/bin/expect

spawn ./test.sh
expect "Enter 'YES' to have this script continue:"
send "YES\r"
interact


来源:https://stackoverflow.com/questions/16716582/how-to-handle-shell-prompt-in-maven

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!