avicohh
avicohh

Reputation: 197

Send command to inner shell

I have this program called "Send_Command.exe" which communicates with LG android phones by openning speiacl shell. The program accepts only one argument - the serial port of the phone.

I wrote batch script which run the "Send_Command.exe", and I want to send commands to the inner shell from the batch.

I tried to create text file contains the inner shell commands, and redirect the input of the shell to the file.

This is my code so far. (shorted version) The full script with the program is in my thread in xda-developers forum.

:: wait for adb cconnection
echo Waiting for device..
adb.exe wait-for-device
echo Device detected!

:: search lg serial port
echo Looking for LG serial port..
for /f "tokens=2*" %%a in ('reg query HKLM\hardware\devicemap\SERIALCOMM /v \Device\LGANDNETDIAG1 2^>nul') do set "comPath=%%~b"
echo Phone found at %comPath%!

:: enter Download mode. (enterDownload file contain single command 'ENTER' which reboot into download mode. this work fine).
echo Rebooting into Download mode..
Send_Command.exe \\.\%comPath% < enterDownload

:: search lg serial port again, this time device already in Download mode
echo Waiting for device..
set comPath=
:wait-for-download
for /f "tokens=2*" %%a in ('reg query HKLM\hardware\devicemap\SERIALCOMM /v \Device\LGANDNETDIAG1 2^>nul') do set "comPath=%%~b"
if "%comPath%" == "" goto wait-for-download
echo Phone found at %comPath%!

:: send command to root the device.
:: installRoot file contains list of commands for root the device.
echo Rooting device..
Send_Command.exe \\.\%comPath% < installRoot

:: reboot (leaveDownload file contain single command 'LEAVE' which leave download mode. this work fine).
Send_Command.exe \\.\%comPath% < leaveDownload

All works well except this line.

Send_Command.exe \\.\%comPath% < installRoot

For some reason it's not always work. I run the same script several times in a row, sometimes he runs the commands in installRoot file, and sometimes he just ignores them. I could not make sense of it.

So I need to find another solution if there is so, how to send list of commands to the shell. Thanks for the help.

Upvotes: 0

Views: 2989

Answers (1)

Alex Roman
Alex Roman

Reputation: 11

Remove the space after < before installRoot and the other script you're piping. Just struggled with this today after years of she'll programming in *nix only. Tricky batch files ;)

Upvotes: 1

Related Questions