0

I created the following TcpConn.bat script that gets the information on open tcp connections from an android device, with an interval of two seconds, running in the adb shell.

:startTCP
adb shell cat /proc/net/tcp
timeout /t 2
goto startTCP

When testing this in my /dev/test/ folder the script ran as expected and gave me the expected output of sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode.

However when I moved it to my /dev/batchFiles/ folder it started running the contents of a different .bat script in that folder (called adb.bat). with the contents

cd C:\Android\sdk\platform-tools
adb logcat -s Unity PackageManager dalvikvm DEBUG

Now in my TcpConn.bat script I execute "adb shell...", which matches the name of "adb.bat" without the extension, so it seems to make a call to this.

My question is though, why would it execute that script? I don't want it to execute the script, but run the adb command I'm not:

  • providing the complete filepath/filename (which would be c:/dev/batchFiles/adb.bat), nor am I using it as a string like "adb"
  • I'm not using call as explained here
  • not using start

Do batch scripts always check the directory for a file matching part of a command and run that file, even if it doesn't have an extension appended to it? If so is there a way to disable this behaviour?


I'm aware I can just rename the "adb.bat" file and be done with it. But want to know why it gets run. The only thing i could somewhat related to this is "How to run batch script without using *.bat extension"

Remy
  • 4,843
  • 5
  • 30
  • 60
  • 5
    `cmd` searches for it's executable in the following order: 1) current working folder 2) path. – Stephan Mar 20 '19 at 15:03
  • 4
    Optionally if you do not want the current batch file to search the current working directory for any executable files (.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC) you can set a special variable to do that. `set NoDefaultCurrentDirectoryInExePath=1`. But a best practice would be to specify the extension of the file name and/or use the full path to the program you are trying to execute. – Squashman Mar 20 '19 at 15:52
  • 3
    It's going to run the first one it finds named `adb` with an executable extension. If it finds the .bat file first, that's what gets run. To prevent that, specify the filename as `adb.exe` instead. – Ken White Mar 20 '19 at 16:53
  • Oh I see. the `adb` i want is in "C:/Android/sdk/platform-tools/adb.exe", but because it *first* finds a file named "adb" in the currect directory is executes that instead of going to the adb.exe I want. is that correct? Thanks for the info guys! – Remy Mar 20 '19 at 17:26

1 Answers1

0

As long as there is a batch file in the same directory as the one you are executing then it will execute that adb.bat file because the windows command prompt will look in the current directory first in search of an executable when you tell your batch file to execute a command.

As far as a solution to your problem I would say if it is possible then change the name of your adb.bat file to something else like adbFile.bat that way you won't be calling it every time you need to call your adb tools from that specific directory.

Zach Pedigo
  • 396
  • 2
  • 9