0
A previous postは、gradleを使って実行されたシェルコマンドの出力を取得する方法を示しています。しかし、これを "adb shell"コマンドに適用しようとすると、空行が表示されます。たとえば、このスクリプト:gradleを使用してadbシェルコマンドの出力を取得するにはどうすればよいですか?
task runTests {
doLast {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'cmd' , '/c', 'dir', 'src'
}
print stdout
}
プリント
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
しかし、この:
task runTests {
doLast {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'cmd' , '/c', 'adb', 'shell' , 'ls'
}
print stdout
}
は、空白行を印刷します。それは出力の各行に空白行を印刷しているようです。私は
commandLine 'cmd' , '/c', 'adb', 'shell' , 'ls' , 'acct'
にコマンドを変更した場合は「ACCT」ディレクトリに以下のファイルがあるので、次に、それはあまり空白行を印刷します。私は、Windowsのコマンドプロンプトで
adb shell ls acct
を実行した場合、それは
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
私は、Windows 8、Androidのメーカー2.2とのGradle 2.10
を実行しているを印刷し、私はアンドレイの提案を試してみました 更新:
task runTests {
doLast {
def testOutput = 'adb shell ls acct'.execute([], project.rootDir).text.trim()
setProperty("archivesBaseName", testOutput)
println testOutput
}
}
しかし、これは、出力の最後の行を出力し、すなわち
uid_1037
お寄せいただきありがとうございます。@ andrey-kopeyko私はこれを試しましたが、出力の最後の行を除いてすべての行に空白行を表示します。 'adb shell ls acct'の場合は、12行の空白行とそれに続く "uid_1037"を出力します。 – Martin
どのようなコードを試しましたか?特定のコードと出力を書き留めてください。 –
'cmd/c'でコマンドをラップする必要はありません。例えば' adb shell ls -l/'のように' adb'を直接実行しようとします。 –