我想使用 Gradle 运行命令行,该命令有一个输出。
我在 Windows powershell 中运行此命令:
./mybat.bat myArgs当我按回车键时,它会打印一些数字,如下所示:
123456
我想用 gradle 运行这个命令并保存这个结果(123456)
这是我在 android build.gradle 文件中编写的一些代码:
task getSomeOutput(type: Exec) {
workingDir "${buildDir}/output"
commandLine 'powershell', './mybat.bat' , 'foo'//this is myArgs for example
}
这可以工作并打印值 123456,但我想将其保存在变量中,我该怎么做?
我发现最好的方法是添加'/c'命令行参数并使用标准输出,这里有一些可能对其他人有帮助的代码:
task getSomeOutput(type: Exec) {
workingDir "${buildDir}/output"
commandLine 'powershell', '/c', './mybat.bat' , 'foo'//this is myArgs for example
standardOutput = new ByteArrayOutputStream()
doLast {
def result = standardOutput.toString()
println "the result value is: $result"
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)