Solved Need To Edit Multiple Batch Files Without External Program

August 29, 2012 at 09:53:43
Specs: Windows 7 Professional N, Intel Core (TM) i5-2450M CPU @ 2.5GHz 2.5GHZ/8GB RAM
Hi I am trying to edit multiple batch files at once with another batch file, or other way unknown to me. I am very inexperienced at batch files so this may not be possible? However, I know I don't want to have to use an "external" app to do it.

I have a program that works by entering simple commands after initialization.

Here is an example:

cd C:\Server\Tools
diagnostics deviceid:0A3D43F50211C008 cameraflash on

So, I have multiple batch files for each command and by calling each of these commands the program will perform a designated action. The problem is that for these commands to work, you have to tell the program which device to talk to (deviceid:xxxxxxxxxxxxxx). That being said it is just as much work to have to edit the deviceid in each batch as it would be to manually call each command in CMD. Any help would be appreciated!


See More: Need To Edit Multiple Batch Files Without External Program

Report •


✔ Best Answer
August 31, 2012 at 10:26:56
Run the below and post the output:

pushd C:\Server\Tools
for /f "tokens=2 delims==&" %%i in (
'diagnostics init'
) do (
diagnostics deviceid:%%i cameraflash on
)
popd
pause

Try this as well:


@echo off & setlocal enabledelayedexpansion
set #=0
pushd C:\Server\Tools
for /f "tokens=2 delims==&" %%i in (
'diagnostics init'
) do (
set /a #+=1
if [!#!]==[1] call :_run %%i
popd
pause
goto :eof
)
:_run
echo diagnostics deviceid:%1 cameraflash on
goto :eof

Tony



#1
August 29, 2012 at 10:38:39
Where do you get these ID's?

@echo off
set /p "id=Enter device ID: "
cd C:\Server\Tools
diagnostics deviceid:%id% cameraflash on

Another option would be to pass the ID as a parameter to each script.

@echo off
set /p "id=Enter device ID: "
cd C:\Server\Tools
diagnostics deviceid:%id% cameraflash on
call secondscript.bat %id%

Then secondscript.bat would contain your next instructions using %1 as the parameter, but it would probably be easier to just combine them all into a single script and CALL labels rather than individual scripts.

@echo off
cd C:\Server\Tools
diagnostics deviceid:%1 cameraflash on
call thirdscript.bat

etc...

Tony


Report •

#2
August 29, 2012 at 13:22:17
Firstly, thanks for your help. This brings me one step closer but I think it can be more automated, if I had given enough info.
The id comes from a CMD window. The first command is:
cd C:\Server\Tools
diagnostics init
Then the program will connect to the device and display the following:
C:\Users\Steve>diagnostics init
DeviceID=SH179T502234&EventName=DeviceStatus&EventData=Connected
DeviceID=SH179T502234&EventName=DeviceStatus&EventData=GettingReady
DeviceID=SH179T502234&EventName=DeviceStatus&EventData=AppInstalled
DeviceID=SH179T502234&EventName=DeviceStatus&EventData=GettingReady
DeviceID=SH179T502234&EventName=DeviceStatus&EventData=AppLaunched
DeviceID=SH179T502234&EventName=DeviceInfo&EventData=ESN:
DeviceID=SH179T502234&EventName=DeviceInfo&EventData=Make:HTC
DeviceID=SH179T502234&EventName=DeviceInfo&EventData=Model:HTC Sensation 4G
DeviceID=SH179T502234&EventName=DeviceInfo&EventData=OSPlatform:Android
DeviceID=SH179T502234&EventName=DeviceInfo&EventData=OSVersion:4.0.3
DeviceID=SH179T502234&EventName=DeviceInfo&EventData=Baseband:unknown
DeviceID=SH179T502234&EventName=DeviceInfo&EventData=Bootloader:1.27.1100
DeviceID=SH179T502234&EventName=DeviceInfo&EventData=BuildNumber:IML74K
DeviceID=SH179T502234&EventName=DisplayStatus&Orientation=ROTATION_0&Size=540x960
DeviceID=SH179T502234&EventName=DeviceStatus&EventData=DeviceReady
This window will remain open until I am finished with the connected device.
From here I use a second CMD window to input the before mentioned commands and communicate to the connected device. I also have no knowledge of the "Device ID', until the device is initially connected and this device id will change for each new device.

Report •

#3
August 30, 2012 at 00:08:20
you need to build an "alias" or "association" or link table. Link the long-and-difficult name with a number or short-"friendly" name. Capture all the "long" names into a text file, then add the "friendly" name, delimited with whatever works (, space, any "safe" char.s (NOT <>=!%) on the same line.
so:
SH179T502234 one
SH179T502235 two

call this file "link"
...
sorry, got to go. Concept should work, but...really tired, gone for wkend.


Report •

Related Solutions

#4
August 30, 2012 at 08:34:29
Firstly, thanks for your help. This brings me one step closer but I think it can be more automated, if I had given enough info.
The id comes from a CMD window. The first command is:
cd C:\Server\Tools
diagnostics init
Then the program will connect to the device and display the following:
C:\Users\Steve>diagnostics init
DeviceID=SH179T502234&EventName=DeviceStatus&EventData=Connected
DeviceID=SH179T502234&EventName=DeviceStatus&EventData=GettingReady
DeviceID=SH179T502234&EventName=DeviceStatus&EventData=AppInstalled
DeviceID=SH179T502234&EventName=DeviceStatus&EventData=GettingReady
DeviceID=SH179T502234&EventName=DeviceStatus&EventData=AppLaunched
DeviceID=SH179T502234&EventName=DeviceInfo&EventData=ESN:
DeviceID=SH179T502234&EventName=DeviceInfo&EventData=Make:HTC
DeviceID=SH179T502234&EventName=DeviceInfo&EventData=Model:HTC Sensation 4G
DeviceID=SH179T502234&EventName=DeviceInfo&EventData=OSPlatform:Android
DeviceID=SH179T502234&EventName=DeviceInfo&EventData=OSVersion:4.0.3
DeviceID=SH179T502234&EventName=DeviceInfo&EventData=Baseband:unknown
DeviceID=SH179T502234&EventName=DeviceInfo&EventData=Bootloader:1.27.1100
DeviceID=SH179T502234&EventName=DeviceInfo&EventData=BuildNumber:IML74K
DeviceID=SH179T502234&EventName=DisplayStatus&Orientation=ROTATION_0&Size=540x960
DeviceID=SH179T502234&EventName=DeviceStatus&EventData=DeviceReady

This window will remain open until I am finished with the connected device.
From here I use a second CMD window to input the before mentioned commands and communicate to the connected device. I also have no knowledge of the "Device ID', until the device is initially connected and this device id will change for each new device.


Report •

#5
August 30, 2012 at 13:59:40
Try this:

@echo off
pushd C:\Server\Tools
for /f "tokens=2 delims==&" %%i in (
'diagnostics init'
) do (
diagnostics deviceid:%%i cameraflash on
)
popd

Tony


Report •

#6
August 31, 2012 at 05:25:41
This returns "The system cannot find the file diagnostics"
Bear in mind the init is a command to initialize the diagnostics program.

Report •

#7
August 31, 2012 at 06:36:33
Sorry, typo, try it again with the updated code.

Tony


Report •

#8
August 31, 2012 at 06:50:48
Getting real close Tony! This did initialze the program (without device id input from me), but it did not cal the "cameraflash on" command.

Report •

#9
August 31, 2012 at 10:26:56
✔ Best Answer
Run the below and post the output:

pushd C:\Server\Tools
for /f "tokens=2 delims==&" %%i in (
'diagnostics init'
) do (
diagnostics deviceid:%%i cameraflash on
)
popd
pause

Try this as well:


@echo off & setlocal enabledelayedexpansion
set #=0
pushd C:\Server\Tools
for /f "tokens=2 delims==&" %%i in (
'diagnostics init'
) do (
set /a #+=1
if [!#!]==[1] call :_run %%i
popd
pause
goto :eof
)
:_run
echo diagnostics deviceid:%1 cameraflash on
goto :eof

Tony


Report •

#10
September 3, 2012 at 15:16:37
:initializer batchfile: starts up the diag program, then goes to interactive
::=== begin init.bat
@echo off & setlocal
cd c:\server\tools
:: really not sure if this part will work or not
set /p pre=<diagnostics init
:attempt to preserve the laborious device-id in one-line file
>currdev echo %pre%
call control.bat
::=== end init.bat

control.bat content:
::=== begin control.bat
@echo off & setlocal
for /f "tokens=2 delims==&" %%a in (currdev) do set pre=%%a
echo device id obtained: %pre%
:top
set x=
set /p x=command:
if not defined x goto :eof
echo executing: deviceid:%pre% %cmand%
diagnostics deviceid:%pre%:%cmand%
goto :top
::=== end control.bat


Report •

Ask Question