How to handle shell prompt in maven

2019-08-01 21:47发布

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.

标签: maven maven-3
5条回答
smile是对你的礼貌
2楼-- · 2019-08-01 22:42

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
查看更多
Explosion°爆炸
3楼-- · 2019-08-01 22:47

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.

查看更多
劳资没心,怎么记你
4楼-- · 2019-08-01 22:50

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.

查看更多
仙女界的扛把子
5楼-- · 2019-08-01 22:53

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

查看更多
时光不老,我们不散
6楼-- · 2019-08-01 22:54

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>
查看更多
登录 后发表回答