1

I have a cmd running 'via' a pipe, created like this:

  console:=TProcess.Create(Nil);
  console.Commandline:='cmd.exe';
  console.Options:=[poUsePipes,poNoConsole,poStderrToOutPut];
  console.CurrentDirectory:=apppath+'data\';
  console.ShowWindow:=swoHIDE;
  console.execute;

Now, my problem is that I'm using cmd to send commands to android device through adb (which is another command line tool). While cmd window itself is hidden, each adb call creates new console window which shortly after closes automatically. How do I hide all those windows altogether?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
laggyluk
  • 195
  • 2
  • 14

1 Answers1

2

Every time you execute adb.exe, it needs to start a new instance of cmd.exe if not already being called by cmd.exe. So, for what you are attempting, simply run cmd.exe one time and keep the session open, and then write commands to it (like ADB commands) over the existing STDIN pipe using the TProcess.Input property.

Better still, you could implement the ADB protocol directly in your own code, communicating over a TCP/USB connection to the device itself. Then you wouldn't need to run adb.exe at all.

Or, to make things a bit simpler, you could run adb.exe as a local server and then communicate with it over a TCP connection instead of through cmd.exe. This is what adb.exe does internally when it is run as a client.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • the doc you linked to is describing *adb server to adb daemon* communication. In my comment I suggested to implement the *adb client* - for which the OP would need to implement even simpler *adb client to adb server* protocol – Alex P. Aug 03 '17 at 23:22
  • @AlexP. yes, what I linked to is the protocol used to communicate with the device itself, then you don't need to run ADB at all. But, if you want to make things simpler, you could run the local ADB server and then communicate with it instead. I added a link to that documentation. – Remy Lebeau Aug 03 '17 at 23:28
  • I thought I'm doing exactly that, 'cmd' TProcess is created once and adb commands are sent through console.Input.WriteBuffer but this results in more console windows popping up as stated in initial question. One way I've found was creating new cmd TProcess with adb as parameter for each calll but this resulted in https://stackoverflow.com/questions/507853/system-error-code-8-not-enough-storage-is-available-to-process-this-command after few hours (at least I think that's the cause). I'll look into alternate means to communicate with adb/device but it doesn't answer the question per se? – laggyluk Aug 04 '17 at 05:49
  • @laggyluk: it has been awhile since I last used ADB, but I don't remember it behaving the way you describe. Executing ADB commands via a single CMD process should not be running new consoles or displaying any pop-up windows. If you run CMD manually, can you reproduce the same issue? Can you provide a [mcve] showing your ADB commands via `TProcess`? – Remy Lebeau Aug 04 '17 at 05:57
  • Ok, hope didn't forget any unit. In any case compiled project with adb binary is in bin.zip https://github.com/laggyluk/adbConsoleTest – laggyluk Aug 04 '17 at 07:00
  • fixed with removing poNoConsole from TProcess startup options. Feel free to edit your answer as it's almost correct :P – laggyluk Aug 04 '17 at 12:53