emendelson Posted May 3, 2020 Posted May 3, 2020 (edited) I have a compiled script that displays a message box with usage information if a user starts it without a parameter. It is a GUI app, but, if a user starts it from the command line with a switch like "/?" or "-h" or "--help", I would like it to print a usage message in the CMD window instead of popping up a message box. I know how to parse the command line - I'm only asking how to send output to the CMD window. Is this possible with AutoIt? I don't want to compile the script as a CLI application, only to send output to the Windows console if it detects the "/?" switch (or something similar) on the command line. Edited May 3, 2020 by emendelson
emendelson Posted May 3, 2020 Author Posted May 3, 2020 Thank you for these. ConsoleWrite() doesn't do the job. I thought of using the second method you mentioned - that is, open a second CMD window and echo the message - but that isn't convenient for a user (it opens a second CMD window), so I'm hoping there's a method that would let the compiled script write the output to the command shell that started it. Meanwhile, thank you for those ideas!
Developers Jos Posted May 3, 2020 Developers Posted May 3, 2020 Compile the script with the CUI option and you should be fine. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Nine Posted May 3, 2020 Posted May 3, 2020 Maybe this is what you are looking for : Opt("SendKeyDelay", 0) Local $handle = WinGetHandle("[CLASS:ConsoleWindowClass]") If Not $handle Then Exit MsgBox (0,"","Console not found") WinActivate ($handle) ControlSend($handle, "", "", "echo This will be send to the current opened console" & @CRLF) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
emendelson Posted May 3, 2020 Author Posted May 3, 2020 Nine's method certainly works. Here is another one that may be clumsy, but only clutters the screen with one extra line of text: Func CmdWindowHelpMessage() Opt("WinTitleMatchMode", 2) If WinActive("cmd.exe") Then _FileCreate(@TempDir & "\usagetxt.bat") Local $u = FileOpen(@TempDir & "\usagetxt.bat", 1) FileWrite($u, "@echo off" & @CRLF & "echo." & @CRLF) FileWrite($u, "echo Usage: MyExecutableScript.exe d:\path\filename" & @CRLF & "echo." & @CRLF) FileWrite($u, "echo [/option=OPTION] [/choice=CHOICE] [/string=STRING]" & @CRLF) FileClose($u) Opt("SendKeyDelay", 0) Send(@TempDir & "\usagetxt.bat {ENTER}") ; Sleep(20) ; FileDelete(@TempDir & "\usagetxt.bat") Exit EndIf EndFunc ;==>HelpMessage You could add CLS to the top of the batch file, but that seems a bit impolite. If there's a better way to do this, I'll be grateful
Nine Posted May 3, 2020 Posted May 3, 2020 Yes I was thinking the same, but I would strongly suggest to use ControlSend as it is way more robust and using the class, you can have the same script with multiple language : french, english, etc. : Opt("SendKeyDelay", 0) ;Run("cmd.exe") Local $handle = WinGetHandle("[CLASS:ConsoleWindowClass]") If Not $handle Then Exit MsgBox (0,"","Console not found") WinActivate ($handle) Local $hFile = FileOpen ("help.cmd", $FO_OVERWRITE) FileWrite ($hFile, _ "@echo off" & @CRLF & _ "echo this is the first line of explaination" & @CRLF & _ "echo this is the second line of explaination" & @CRLF & _ "echo this is the third line of explaination" & @CRLF & _ "echo this is the fourth line of explaination" & @CRLF & _ "echo this is the fifth line of explaination" & @CRLF ) FileClose ($hFile) ControlSend($handle, "", "", "help" & @CRLF) Sleep (500) FileDelete ("help.cmd") and calling the script help, is more appropriate for the user emendelson 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now