A previous post shows how to get the output of a shell command executed using gradle. However, when I try to apply this to an "adb shell" command, it prints blank lines. For example, this script:
task runTests {
doLast {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'cmd' , '/c', 'dir', 'src'
}
print stdout
}
prints
Volume in drive C is Windows
Volume Serial Number is 0AEC-E2A0
Directory of C:\Users\mb\android\project
12/02/2016 12:37 PM <DIR> .
12/02/2016 12:37 PM <DIR> ..
12/02/2016 12:37 PM <DIR> androidTest
12/02/2016 12:37 PM <DIR> main
12/02/2016 12:37 PM <DIR> test
0 File(s) 0 bytes
5 Dir(s) 13,056,221,184 bytes free
But this:
task runTests {
doLast {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'cmd' , '/c', 'adb', 'shell' , 'ls'
}
print stdout
}
prints blank lines. It seems to be printing a blank line for each line of output. If I change the command to
commandLine 'cmd' , '/c', 'adb', 'shell' , 'ls' , 'acct'
Then it prints less blank lines because there are less files in the 'acct' directory. If I run
adb shell ls acct
in the Windows Command Prompt, it prints
cgroup.clone_children
cgroup.event_control
cgroup.procs
cpuacct.stat
cpuacct.usage
cpuacct.usage_percpu
notify_on_release
release_agent
tasks
uid
uid_10006
uid_10014
uid_1037
I'm running Windows 8, Android Studio 2.2 and Gradle 2.10
Update I tried Andrey's suggestion:
task runTests {
doLast {
def testOutput = 'adb shell ls acct'.execute([], project.rootDir).text.trim()
setProperty("archivesBaseName", testOutput)
println testOutput
}
}
But this prints the last line of the output, i.e.
uid_1037