目前我正在使用以下解决方法(描述here)来隐藏“mypassword”,但我想知道是否有更优雅的解决方案?
的build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project default="test">
<target name="test" depends="">
<echo message="Testing..."/>
<echo message="Turning verbose off... you should NOT see the arguments..."/>
<script language="javascript">
var logger = project.getBuildListeners().firstElement();
// 2 works to turn off verbose
logger.setMessageOutputLevel(2);
</script>
<exec dir="." executable="cmd">
<arg line="/c dummy.bat mypassword"/>
</exec>
<echo message="Turning verbose on... you should see the arguments..."/>
<script language="javascript">
var logger = project.getBuildListeners().firstElement();
// 3 works to turn verbose back on
logger.setMessageOutputLevel(3);
</script>
<exec dir="." executable="cmd">
<arg line="/c dummy.bat mypassword"/>
</exec>
</target>
</project>
dummy.bat
@echo off
echo dummy
输出
test:
[echo] Testing...
[echo] Turning verbose off... you should NOT see the arguments...
[exec] dummy
[echo] Turning verbose on... you should see the arguments...
[exec] Current OS is Windows XP
[exec] Executing 'cmd' with arguments:
[exec] '/c'
[exec] 'dummy.bat'
[exec] 'mypassword'
[exec]
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.
[exec] dummy
谢谢你的回应,但是这不是我要找的。我不想在远程主机上运行命令。我正在寻找在Ant脚本正在运行的主机上执行一个命令,这需要敏感的参数。我已经更新了这个问题来更详细地解释这个问题。 – Jesse 2013-04-10 02:34:08
@Jesse更新了我的答案。 – 2013-04-10 08:58:17
再次感谢您马克,但我已经在使用NOPASSWD,所以我不需要输入密码来执行sudo命令。我的问题涉及如何在示例中隐藏“Userid = username/mypassword @ blah”。我已经从示例中删除了sudo以清除此问题。 – Jesse 2013-04-10 14:51:25