gpt4 book ai didi

ant - 如何从 Ant 构建脚本执行交互式应用程序?

转载 作者:行者123 更新时间:2023-12-04 16:07:32 25 4
gpt4 key购买 nike

来自 http://ant.apache.org/manual/Tasks/exec.html :

Note that you cannot interact with the forked program, the only way to send input to it is via the input and inputstring attributes. Also note that since Ant 1.6, any attempt to read input in the forked program will receive an EOF (-1). This is a change from Ant 1.5, where such an attempt would block.



如何从 ant 启动交互式控制台程序并与之交互?

我想做的类似于 drush sqlc功能,即使用正确的数据库凭据启动 mysql 客户端解释器,但不限于此用例。

这是一个示例用例:
<project name="mysql">
<target name="mysql">
<exec executable="mysql">
<arg line="-uroot -p"/>
</exec>
</target>
</project>

使用 ant 运行时:
$ ant -f mysql.xml mysql
Buildfile: /home/ceefour/tmp/mysql.xml

mysql:
Enter password:

BUILD SUCCESSFUL
Total time: 2 seconds

输入密码后,立即退出。

将此与直接在 shell 上执行时发生的情况进行比较(预期行为):
$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1122
Server version: 5.1.58-1ubuntu1 (Ubuntu)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

最佳答案

您可以通过 shell 启动您的命令,将标准输入/输出/错误从/到/重定向到 /dev/tty ,对应于 controlling terminal的过程。

<target name="dbshell" description="Open a shell for interactive tasks">
<exec executable="/bin/sh">
<arg value="-c"/>
<arg value="mysql -u root -p &lt; /dev/tty &gt; /dev/tty 2&gt; /dev/tty"/>
</exec>
</target>

关于ant - 如何从 Ant 构建脚本执行交互式应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6303405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com