Page 1 of 2

CliSAK class - 2021/06/26 AHK v1

Posted: 10 Jan 2020, 10:24
by TheArkive
Cli - Swiss Army Knife v4 (CliSAK)


AHK v2 version/discussion moved to this thread.

Usage:
  • For one-time data collection: var := CliData(inCommand)
  • For streaming collection: obj := new cli(inCommand, options := "")
Please see example script for detailed examples.

Features:
  • New wrapper function CliData(inCommand) for easy inline one-time data collection from a program.
  • Easy collection of streaming output with callback functions, can handle multiple CLI sessions simultaneously
  • Creates a hidden console window so that CTRL+C and CTRL+Break can still be passed to halt execution with hotkey, button, etc.
  • Interactive CLI mode in the background, write to StdIn directly.
  • Capture StdErr separately, if desired, and pass data to optional callback.
  • Pass dynamically created multi-line batch commands executed in succession.
  • Define a callback for when a command returns and the prompt is displayed again.
  • Define a "Quit String" to automatically halt execution, clean up processes and handles, and trigger a callback.
  • Capture console animations like incrementing percent, or progress bar.
The following CLI environment prompts (shells) can be detected:
  • Windows batch
  • netsh
  • Android ADB
  • SSH
If you would like support for a new shell prompt, post a msg with details so I can research and add the new environment.

=======================================================================
UPDATES:
=======================================================================

:arrow: Download on GitHub

Huge thanks to the following users:
@segalion , @Sweeet, @sean , @maraksan_user, @SKAN , @HotKeyIt , @maz_1, @lexikos , @TheGood, @just me, @joedf
Details of their contributions are in the comments of the CLI class library. They have done a LOT. Without their contributions, I would not have gained the knowledge or the means to make this.

I'm happy to hear any commets/critiques to make this library more useful, fast, and memory-efficient.

Re: command line support - cli class - the next level ... (hopefully?)

Posted: 10 Jan 2020, 10:54
by TheArkive
Sorry for the errant post, (and now double post).

The OP is complete now.

Re: CLI class - v3 - Updated: 2020/02/05

Posted: 05 Feb 2020, 13:48
by TheArkive
*** New / Updated *** [2020/02/05]
  • interactive cli mode in the background, write to StdIn, no longer rough around the edges...
  • Capture StdErr separately, if desired, and pass data to optional callback
  • Batch mode, pass a large, dynamically created, multi-line batch, commands executed in succession
  • Define a callback for when a command returns and the prompt is displayed again
  • Capture console animations like incrementing percent, or progress bar

Re: CliSAK class - v4 - Updated: 2020/02/06

Posted: 06 Feb 2020, 06:09
by TheArkive
Update: 2020/02/06
  • Improved mode "m" to allow batch commands.
  • Fixed mode "m" handling of FreeConsole and AttachConsole when sending CTRL signals
    (myObj.CtrlC() would kill the script in some cases)
  • Improved batch command handling in mode "b" and "m"
    StdOutCallback() function recieves "__Batch Finished__" when complete
  • Fixed up the Examples to function as intended

Re: CliSAK class - v4 - Updated: 2020/02/06

Posted: 19 Apr 2020, 10:41
by burque505
@TheArkive, this is certainly a comprehensive tool. The examples are very thorough. Thank you!
Regards,
burque505

Re: CliSAK class - v4 - Updated: 2020/02/06

Posted: 20 Apr 2020, 01:34
by TheArkive
@burque505, glad this worked out for ya :-) ... I was wondering if anyone would get any usage out of this. Saw your post in MsgBox2 as well. I'll be posting an AHK v2 version of those soon.

Re: CliSAK class - v4 - Updated: 2020/02/06

Posted: 24 Apr 2020, 06:28
by toralf
I‘ll try it on one script of mine that captures stream from consol. Thanks for creating this tool.

Re: CliSAK class - v4 - Updated: 2020/02/06

Posted: 25 Apr 2020, 01:48
by TheArkive
@toralf
Hey man, just wondering if this script helped at all.

Re: CliSAK class - v4 - Updated: 2020/02/06

Posted: 12 May 2020, 04:47
by hasantr
TheArkive Thank you for this wonderful Class. I am considering using it for a medium-sized work.
I did several amateur tests. Not everything can be done in a single line, this is a bit difficult, but there are many good features for the future.

I was curious to do something.
Is it possible to see the whole stream without hiding the console? Yes, I want to get Stdout, but I want everything to appear on the console as well. And when the process is over, the console will not shut down and it will be on standby.

Re: CliSAK class - v4 - Updated: 2020/02/06

Posted: 12 May 2020, 06:10
by TheArkive
@hasantr
shouldn't be a problem, but you might need to know how big the output is going to be ahead of time.

I'll look into adding an option to detect the output size and to use all the output for the stream. That should also be possible.

EDIT: just took a look at the code... Not sure if it will be possible without predetermining the size. This feature, mode "m", basically reads from the console buffer, not from StdOut. When you resize a console window, of course it can change the display of the streaming output. So the size of the console is the most important factor. If you don't know the dimensions of your output, then you'll just have to use a larger output, but of course the larger the grid specified, the more of a performance hit you risk.

This is not meant for scrolling output, like you would get from StdOut. It sounds like you want to capture StdOut and get the streaming output? I didn't code this class with that feature in mind, but sounds like it should be possible. Though that would be complex. How do you plan on using it?

Please correct me if my assumptions are wrong.

Re: CliSAK class - v4 - Updated: 2020/02/06

Posted: 12 May 2020, 06:48
by hasantr
I thought it would be very normal. Normally the console is not as it works. It works in the background. I learned this. Then I must stop asking for it. I realized that there was an irrelevant request especially for this class.

I want to make an application that will send commands to Android phones with ADB. I wanted the user to be able to see which command went and what he returned, via cmd.

Re: CliSAK class - v4 - Updated: 2020/02/06

Posted: 12 May 2020, 09:16
by BNOLI
hasantr wrote:
12 May 2020, 06:48
I thought it would be very normal. Normally the console is not as it works. It works in the background. I learned this. Then I must stop asking for it. I realized that there was an irrelevant request especially for this class.

I want to make an application that will send commands to Android phones with ADB. I wanted the user to be able to see which command went and what he returned, via cmd.
You could try to send commands/strings to Android/iOS phones using UDP/TCP.
http://sanyei-imports.com/scott/repo/UDPSend/udpsend.html
http://sanyei-imports.com/scott/repo/UDPListen/udplisten.html
https://automagic4android.com/

Re: CliSAK class - v4 - Updated: 2020/02/06

Posted: 12 May 2020, 09:33
by hasantr
BNOLI wrote:
12 May 2020, 09:16
hasantr wrote:
12 May 2020, 06:48
I thought it would be very normal. Normally the console is not as it works. It works in the background. I learned this. Then I must stop asking for it. I realized that there was an irrelevant request especially for this class.

I want to make an application that will send commands to Android phones with ADB. I wanted the user to be able to see which command went and what he returned, via cmd.
You could try to send commands/strings to Android/iOS phones using UDP/TCP.
http://sanyei-imports.com/scott/repo/UDPSend/udpsend.html
http://sanyei-imports.com/scott/repo/UDPListen/udplisten.html
https://automagic4android.com/
Thanks BNOLI. Maybe I can do the data transfer part with this.
Still, this library would be needed.
 I'm not interested in just sending data.

Re: CliSAK class - v4 - Updated: 2020/02/06

Posted: 12 May 2020, 10:08
by burque505
@hasantr, take a look at GuiCmd.ahk which is unfinished but might work for you if you fix it up. :D
Regards,
burque505

Re: CliSAK class - v4 - Updated: 2020/02/06

Posted: 12 May 2020, 15:49
by hasantr
burque505 wrote:
12 May 2020, 10:08
@hasantr, take a look at GuiCmd.ahk which is unfinished but might work for you if you fix it up. :D
Regards,
burque505
I wish I had so much knowledge. :)
Thanks a lot anyway.

I will use the Clisak library for my work. I may need some forward-looking features. Can TheArkive explain the nomenclature to us? What does Clisak mean?

Thanks again to everyone. If some of the statements I wrote strange to you, this is the fault of google translate.

Re: CliSAK class - v4 - Updated: 2020/02/06

Posted: 13 May 2020, 00:36
by TheArkive
@hasantr
CLISAK means - CLI Swiss Army Knife

What is the problem you have with the output? If you give me specifics of what kind of behavior you want then maybe I can improve CLISAK. Are you trying to collect StdOut and streaming animations at the same time?

I actually have made my own app that communicates with android phones over ADB, and this class is a core part of it.

Just let me know what you are trying to do man ;-)

Show me what ADB commands you are trying to send, and explain what kind of info you are trying to collect. Maybe I can help this way.

Re: CliSAK class - v4 - Updated: 2020/02/06

Posted: 20 May 2020, 04:43
by BNOLI
@TheArkive was so kind as to answer a question (in remarkable detail) that I've questioned at another thread ...
So just for the records ... and whom it may concern:

"I've seen your class, but haven't seen (while I'm sure it's there) the explicitly requested option (...) to switch off the stealth-mode for debugging? Would you mind pointing out where to find that, or provide a sample command line with its parameter to show how to accomplish that? Thx a lot :)"

Well, to see his answers regarding my question just click :arrow: here :)

Thx for sharing your knowledge with us. Much appreciated :thumbup:

Re: CliSAK class - v4 - Updated: 2020/02/06

Posted: 20 May 2020, 05:39
by TheArkive
@BNOLI thanks :-) ... and of course I'm glad to be able to help :-)

I added an edit to my last post in that thread, to explain why my script creates a console window that won't show anything. It's for receiving "Control Signals", ie. CTRL+Break and CTRL+C. Need to have a window for that.

Re: CliSAK class - Updated: 2020/05/24 - AHK v1 / v2

Posted: 24 May 2020, 12:32
by TheArkive
Update: 2020/05/24
  • add mode f to filter control codes from SSH prompt
  • added prompt detection for SSH prompt

Re: CliSAK class - Updated: 2020/05/26 - AHK v1 / v2

Posted: 26 May 2020, 02:31
by TheArkive
Update:2020/05/26
  • added CLI object as parameters to callback functions
  • .output has been renamed to .stdout
  • .error has been renamed to .stderr
  • now when using stdout / stderr callback functions .stdout and .stderr will continue to accumulate so you can check or clear these values as needed
  • examples have been updated to reflect the changes
  • OP updated to show current list of prompts supported with cliPromptCallback() function