title: Send command to inner shell
body: <p>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.</p>
  
  <p>I wrote batch script which run the "Send_Command.exe", and I want to send commands to the inner shell from the batch.</p>
  
  <p>I tried to create text file contains the inner shell commands, and redirect the input of the shell to the file.</p>
  
  <p>This is my code so far. (shorted version)
  The full script with the program is in
  <a href="http://forum.xda-developers.com/lg-g3/general/guide-root-lg-firmwares-kitkat-lollipop-t3056951" rel="nofollow">my thread in xda-developers forum</a>.</p>
  
  <pre><code>:: 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^&gt;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% &lt; 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^&gt;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% &lt; installRoot
  
  :: reboot (leaveDownload file contain single command 'LEAVE' which leave download mode. this work fine).
  Send_Command.exe \\.\%comPath% &lt; leaveDownload
  </code></pre>
  
  <p>All works well except this line.</p>
  
  <pre><code>Send_Command.exe \\.\%comPath% &lt; installRoot
  </code></pre>
  
  <p>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.</p>
  
  <p>So I need to find another solution if there is so, how to send list of commands to the shell.
  Thanks for the help.</p>