Issuing Shell Commands

Adb provides an ash shell that you can use to run a variety of commands on an emulator or device. The command binaries are stored in the file system of the emulator or device, in this location:

You can use the shell command to issue commands, with or without entering the adb remote shell on the emulator/device. To issue a single command without entering a remote shell, use the shell command like this:

adb [-d|-e|-s {<serialNumber>]] shell <shellCommand>

To drop into a remote shell on a emulator/device instance, use the shell command like this:

When you are ready to exit the remote shell, use CTRL+D or exit to end the shell session.

The sections below provide more information about shell commands that you can use. Examining sqlite3 Databases from a Remote Shell

From an adb remote shell, you can use the sqlite3 command-line program to manage SQLite databases created by Android applications. The sqlite3 tool includes many useful commands, such as .dump to print out the contents of a table and .schema to print the SQL CREATE statement for an existing table. The tool also gives you the ability to execute SQLite commands on the fly.

To use sqlite3, enter a remote shell on the emulator instance, as described above, then invoke the tool using the sqlite3 command. Optionally, when invoking sqlite3 you can specify the full path to the database you want to explore. Emulator/device instances store SQLite3 databases in the folder /data/data/<package name>/databases/.

Here's an example:

Once you've invoked sqlite3, you can issue sqlite3 commands in the shell. To exit and return to the adb remote shell, use exit or CTRL+D.

UI/Application Exerciser Monkey

The Monkey is a program that runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.

The simplest way to use the monkey is with the following command, which will launch your application and send 500 pseudo-random events to it.

$ adb shell monkey -v -p your.package.name 500

For more information about command options for Monkey, see the complete UI/Application Exerciser Monkey documentation page. Other Shell Commands

The table below lists several of the adb shell commands available. For a complete list of commands and programs, start an emulator instance and use the adb -help command.

adb shell ls /system/bin

Help is available for most of the commands.

Shell Command

Description

Comments

dumpsys

Dumps system data to the screen.

The Dalvik Debug Monitor Service (DDMS) tool offers integrated debug environment that you may find easier to use.

dumpstate

Dumps state to a file.

logcat [<option>]... [<filterspec>]...

Enables radio logging and prints

$ adb -s emulator-5554 shell

# sqlite3 /data/data/com.example.google.rss.rssexample/databases/rssitems.db SQLite version 3.3.12 Enter ".help" for instructions enter commands, then quit... sqlite> .exit output to the screen.

dmesg

Prints kernel debugging messages to the screen.

Starts (restarts) an emulator/device instance.

stop

Stops execution of an emulator/device instance.

0 0

Post a comment