CliSAK class - 2020/11/12

Post your working scripts, libraries and tools
User avatar
TheArkive
Posts: 403
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

CliSAK class - 2020/11/12

10 Jan 2020, 10:24

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 := "")
I highly recommend you try the wget.exe example with Example #8. It clearly illustrates how to isolate an incrementing percent or any other "animated" block of text on the command line. Check the comments in the example script for instructions.

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.
Last edited by TheArkive on 01 Dec 2020, 11:30, edited 53 times in total.
User avatar
TheArkive
Posts: 403
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

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

10 Jan 2020, 10:54

Sorry for the errant post, (and now double post).

The OP is complete now.
User avatar
TheArkive
Posts: 403
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

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

05 Feb 2020, 13:48

*** 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
User avatar
TheArkive
Posts: 403
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

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

06 Feb 2020, 06:09

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
burque505
Posts: 1415
Joined: 22 Jan 2017, 19:37

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

19 Apr 2020, 10:41

@TheArkive, this is certainly a comprehensive tool. The examples are very thorough. Thank you!
Regards,
burque505
User avatar
TheArkive
Posts: 403
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

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

20 Apr 2020, 01:34

@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.
toralf
Posts: 793
Joined: 27 Apr 2014, 21:08
Location: Germany

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

24 Apr 2020, 06:28

I‘ll try it on one script of mine that captures stream from consol. Thanks for creating this tool.
ciao
toralf
User avatar
TheArkive
Posts: 403
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

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

25 Apr 2020, 01:48

@toralf
Hey man, just wondering if this script helped at all.
User avatar
hasantr
Posts: 747
Joined: 05 Apr 2016, 14:18
Location: İstanbul

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

12 May 2020, 04:47

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.
User avatar
TheArkive
Posts: 403
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

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

12 May 2020, 06:10

@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.
User avatar
hasantr
Posts: 747
Joined: 05 Apr 2016, 14:18
Location: İstanbul

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

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.
BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

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

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/
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !
User avatar
hasantr
Posts: 747
Joined: 05 Apr 2016, 14:18
Location: İstanbul

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

12 May 2020, 09:33

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.
burque505
Posts: 1415
Joined: 22 Jan 2017, 19:37

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

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
User avatar
hasantr
Posts: 747
Joined: 05 Apr 2016, 14:18
Location: İstanbul

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

12 May 2020, 15:49

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.
User avatar
TheArkive
Posts: 403
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

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

13 May 2020, 00:36

@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.
BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

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

20 May 2020, 04:43

@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:
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !
User avatar
TheArkive
Posts: 403
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

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

20 May 2020, 05:39

@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.
User avatar
TheArkive
Posts: 403
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

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

24 May 2020, 12:32

Update: 2020/05/24
  • add mode f to filter control codes from SSH prompt
  • added prompt detection for SSH prompt
User avatar
TheArkive
Posts: 403
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

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

26 May 2020, 02:31

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

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 28 guests