ADB logcat batch never ends - batch-file

I am trying to create a batch file that will do some ADB commands that I use on a daily basis. I am stuck with adb logcat because the logcat never ends. Is there a way to end it after so many seconds? Currently I have
:logcat
adb logcat
pause>nul|set /p "=Press any key to return to the menu"<nul&echo(
cls
goto start
Thinking that pause would allow me to manually end it when I was done getting what I needed from the log.
Is there a way to end the command?
Thanks

You could use
timeout DURATION adb logcat
to stop the logcat after DURATION (default is in seconds).
Another way of using adb is:
adb logcat -d
This will get the log and terminate the command immediately.
I don't know any other way to stop the logcat after some seconds, except CTRL+C.

Related

log in adb shell "interactive mode" and "non-interactive mode"

I'm writing script to run iperf on linux device accessible via adb.
From a terminal, when I run the command: adb shell iperf -c ......
I get the log of the command 50 s after the command starting.
inconvenient: during 50 s you are not sure that iperf has started
I tried the logcat command (logcat --pid ...), It gives the same result.
From a terminal, when I enter adb session first and then I run the command: iperf -c .....
I get the log of the command in real time.
inconvenient: I'm not able to automate the procedure, because I have to start the adb session first
For the first use case: Is there a way to force "log flush" in order to get the log in real time?
For the second use case: Is there a way to send commands to already opened adb shell session?
Is there any other ways to launch iperf on device and get the log in real time?
The solution i found is the library pexpect that allow to interact with adb session.

Adb Logcat to print only live traces

I am using following command which prints android device logs from connected device buffer in my desktop.
adb logcat
Now requirement is, i am running a test and want to see the output of current action in logs.
That is i need logs only since when i start logging command.
i don't want logs from the buffer or the logs prior to time when logging is started.
Also i don't want to clear the buffer using -c argument. because somebody (some other process) may need buffered traces during testing
adb logcat --live-trace
Thanks in advance for the help.
i found the perfect way to do it!
Read current time from the device only.
adb shell echo $(date +'%Y-%m-%d %H:%M:%S')
Merge the above output with ".000" (just adding milliseconds) and save into some variable say %timestamp%.
Then,
adb logcat -v threadtime - D -T %timestamp%
You can use it in one command:
adb logcat -v threadtime - D -T $(adb shell echo $(date +'%s')).000

trying to write a .bat file to auto login and exit

im tyring to write a bat file to ensure i am logged into a remote pc by a certain time so that some other auto processes can run on that pc.
heres where i am
cmdkey /generic:TERMSRV/server /user:**** /pass:*****
mstsc /v:server
ping 8.8.8.8 -n 10
taskkill /im mstsc.exe /f
problem im facing is that after lauching the remote pc is doesnt move to the ping until i manually close the cmd window
seems really simple, im just blanking. and if i could schedule it and save my creds in task scheduler i would, current gp doesnt allow me to.
thanks in advance.
You can call mstsc with start to run mstsc independently of the batch script.
start "" mstsc /v:server

How to stop and restart Audio Service using a batch file?

I made a batch file with the following line
net stop audiosrv & net start audiosrv
It just flashes and closes, not actually doing the command. I think I saw something about administrator privileges in the command window but it flashed too fast to tell. What is wrong?
Create a new text file.
Then, paste the following code into it.
#echo off
net stop audiosrv
pause
net start audiosrv
pause
Save the file as a bat file.
Open the bat file as admin.
Here find a script for running a batch file as an admin
#echo off
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
net stop audiosrv
pause
net start audiosrv
pause
A more comprehensive batch file approach:
#echo off
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
net stop audiosrv
pause
net stop AudioEndpointBuilder
pause
net start AudioEndpointBuilder
pause
net start audiosrv
pause
The audio service is started by Windows using local system account and therefore it is not possible to stop this service without administrator privileges as command net outputs.
The solution is clicking with right (secondary) mouse button on batch file and click with left (primary) mouse button in context menu on Run as Administrator as Magoo already suggested before.
For testing a batch file just created, it is always useful to open a command prompt window and run the batch file from within this window by entering name (with path if needed) and hitting RETURN. A shortcut for opening a command prompt window can be found in Accessories menu of Windows start menu, or the command cmd.exe is executed which also opens a console window.

Call command from exe in bat file

I am currently developing a android app and I am debugging wireless.
Every time I want to do this, I need to open the cmd in a specific direction and type:
adb
adb connect 'some ip'
adb is a exe and adb connect is some command in adb.exe
I was trying to write a simple bat file for this and I found this on the internet:
START C:\Andriod\adb.EXE
As you know, this only starts the adb.
I could not find how to call this command, propbably because I do not know the correct name for it. Can someone help me?
Use CALL command like this in batch:
#echo off
call C:\Andriod\adb.EXE
adb -s [yourdeviceserialnumberhere] shell
adb connect {ip:host}
http://www.droidforums.net/forum/android-hacks-help/6865-how-use-adb-all-commands-options.html

Resources