Call command from exe in bat file - batch-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

Related

Unable to access system storage in adb shell

I was trying to install a gsi with DSU sideloader. It needs me to type a command using adb to initialize the installation. But I keep getting this error while running the adb shell command on my pc
adb shell sh/storage
/system/bin/sh: sh/storage: inaccessible or not found
The actual command was adb shell sh/storage/emulated/0/Dsu/workspace_dsuhelper/install
Which also results in the same error: /system/bin/sh: sh/storage/emulated/0/Dsu/workspace_dsuhelper/install : inaccessible or not found.
I know that /storage/emulated/0... exists but I am unable to access it. What could be the issue?
use this command to get the storage status
adb shell df /data

How can I Check with adb that there is an external storage Card?

I want to check a file in a sdcard but I have to use ADB.
I made this :
adb shell ls $EXTERNAL_STORAGE
It prompts me a list of directories but it's not my sdCard.
How can I find a file in my sdcard using adb ?
#paralleles. You can use the following adb command below to check if an external storage card exists:
adb shell echo /$EXTERNAL_STORAGE
If the above command executes successfully, you'll see a similar output as below :
Alternatively you can start an adb shell session and traverse the directory so as to find the desired file in your sdcard as follows :
adb shell
cd $EXTERNAL_STORAGE
If the above commands executes successfully, you'll see a similar output as below (depending on the files/folders in your SdCard):

windows, Putty, pscp combined in to a single batch file, is it possible?

I'm having trouble getting an answer to my question, in laymens terms. It is probably my lack of knowledge on the subject so, I'm dumbing down the question. I have a windows machine that I run the putty tool from and connect to a linux box. I run " killall /bob/bin/myfile.out " then close putty then type in a cmd prompt pscp.exe myfilet.out.2.3.4 root#192.168.1.1:/bob/bin/myfile.out . Can someone show me how to combine these into a single windows batch file? thank you
You could use the free command line tool Plink to run commands on external servers via SSH.
#echo off
Plink root#192.168.1.1 "killall /bob/bin/myfile.out"
pscp.exe myfilet.out.2.3.4 root#192.168.1.1:/bob/bin/myfile.out || echo an error occurred when copying the file.
the command after || on the second line will only run if an error level is set by the previous command.
I can't add comments yet, but can you elaborate on how you login with putty, but not do the exact same thing with plink? Plink not only accepts all the same options as putty, but if you have a saved session in putty, you can access it from plink. Without any subcommands, plink should essentially make you CMD shell look like a crude putty window, with subcommands, it will execute them and return:
C:\Users\riglerjo>plink savedputtysession
Using username "rigler".
# hostname
s9-chicago.accountservergroup.com
-bash-3.2$ exit
logout
Run the remote command as an option on plink:
C:\Users\riglerjo>plink savedputtysession hostname
s9-chicago.accountservergroup.com

adb push only if file doesn't exist or has changed

For a program I am using ADB to transfer a file from the computer to mobile phone.
Using adb push overwrites every existent file and thus takes ages to finish.
adb sync does only push the file if it exists on the phone AND contains other data than the local version.
Is there any midway solution? I want the file to be transferred if it doesn't exist or is changed, but not, if it is the same as on the computer. Is there a way to achieve this?
The best way to do this is to first check if the file exists and if it does then sync it and if it does not then push.
Skeleton for a batch script to do this:
FILENAME_RESULT=$(adb shell ls / | tr -d '\015'|grep '^fileName$')
if [ -z "$FILENAME_RESULT" ];
then
REM adb push because the file was not found
else
REM adb sync because the file was found
fi
adb push --sync /local/file /sdcard/remote/file
From adb --help
adb push [--sync] [-zZ] LOCAL... REMOTE copy local files/directories to device --sync: only push files that are newer on the host than the device. -z: enable compression -Z: disable compression
There's a really easy way to do this with adb-sync (https://github.com/google/adb-sync).
adb-sync is a tool to synchronize files between a PC and an Android device using the ADB (Android Debug Bridge).

Encountering erros when trying to automate PSFTP command using a .bat file

In looking at other posts, "Batch file for PuTTY/PSFTP file transfer automation", regarding automating the PSFTP command in a .bat file so that I can setup a Windows Scheduled Task, I tried the following but got the error below:
In the .bat file that I'm executing I have the following lines:
#echo off
cd "c:\PuTTY"
psftp 999.99.999.999 -l XXXXXIO -i testGSX.ppk -b DownloadDiscoverReports.txt
In the DownloadDiscoverReports.txt file I have the following lines:
lcd c:\Reports\GSXDLFILES\ALLRPTS
cd /DSCVROUT/ALLRPTS/
mget *ALLRPTS%POLLABLE*
lcd c:\Reports\GSXDLFILES\XMIT81
cd /DSCVROUT/XMIT81/
mget *XMIT81%POLLABLE*
The error I'm getting when I execute the .bat file from my C:\ is:
C:\>gsx_dl.bat
psftp: no hostname specified; use "open host.name" to connect
New local directory is c:\Reports\GSXDLFILES\ALLRPTS
psftp: not connected to a host; use "open host.name"
C:\PuTTY>
Any suggestions/direction on how to fix this issue would be appreciated. Thank you.
This issue has been resolved. PuTTY support responded to my issue and I entered a -v switch to my command and found that my KEY had expired and that was the issue.
Thanks anyway.

Resources