Jump to content

Search the Community

Showing results for tags 'command line'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 14 results

  1. GetOpt.au3 v1.3 If you've ever dabbled in C (or Python, Perl etc) then you might have heard of getopt() (Wiki entry). Well, I wrote this UDF to get that functionality into AutoIt. Some searching around here on the forum did turn up some other UDFs in this direction, but I decided to write my own port anyway and parallel the implementation in the C library. It's still missing a few things but on a whole it does the job really well. It's now pretty much complete. And I want to share it with you all. So here it is. If you want to handle the command line options passed to your script or program like a master, then this is the UDF for you! Main features: Parses DOS style options as well as GNU style options alike.Handles both short and long options.Define options that must have arguments when used.Define and handle suboptions (-s=foo,bar=quux,baz).Supports + and /- option modifiers.Casts string arguments to AutoIt variants, e.g. -a=yes becomes True.Easy access to any passed operand that's not an option.Some examples of invoking scripts: Script.au3 -a -b=10 --long-option file.txt Script.au3 /A /B:10 /Long-Option file.txtAs you see you can use both styles on the command line (as a matter of fact, at this moment you could even mix them but that wouldn't be good practice). In your script you just set the options you want to detect with _GetOpt_Set() and then iterate through each option with _GetOpt(). The 'file.txt' is available through _GetOpt_Oper(). See GetOpt-Example.au3 below for a step-by-step walkthrough of using GetOpt.au3. The UDF: GetOpt.au3 (+43) GetOpt-Example.au3: A demo of GetOpt.au3 #include <GetOpt.au3> #include <Array.au3> ; For demo purposes only. If 0 = $CmdLine[0] Then ; Create our own example command line. Run(FileGetShortName(@AutoItExe) & ' ' & FileGetShortName(@ScriptFullPath) & ' -a=no -b=42 -c=0.5 /Windows:' & @OSVersion & ' -z --required -s=foo,bar=quux,baz +p /-M -- -w=ignored Hello World!') Exit EndIf _GetOpt_Demo() Func _GetOpt_Demo() Local $sMsg = @ScriptName & ' for GetOpt v' & $GETOPT_VERSION & '.' & @CRLF & 'Parsing: ' & _ArrayToString($CmdLine, ' ', 1) & @CRLF & @CRLF; Message. Local $sOpt, $sSubOpt, $sOper ; Options array, entries have the format [short, long, default value] Local $aOpts[9][3] = [ _ ['-a', '--a-option', True], _ ['-b', '--b-option', False], _ ['-c', '--c-option', 'c option argument'], _ ['/W', '/Windows', 'windows style argument'], _ ; For demo purposes styles are mixed. ['-r', '--required', $GETOPT_REQUIRED_ARGUMENT], _ ; This option requires an argument. ['-s', '--suboption', $GETOPT_REQUIRED_ARGUMENT], _ ; option with suboptions. ['-p', '--plus', Default], _ ['/M', '/Minus', Default], _ ['-h', '--help', True] _ ] ; Suboptions array, entries have the format [suboption, default value] Local $aSubOpts[2][2] = [ _ ['foo', 47], _ ['bar', True] _ ] _GetOpt_Set($aOpts) ; Set options. If 0 < $GetOpt_Opts[0] Then ; If there are any options... While 1 ; ...loop through them one by one. ; Get the next option passing a string with valid options. $sOpt = _GetOpt('abcwr:s:pmh') ; r: means -r option requires an argument. If Not $sOpt Then ExitLoop ; No options or end of loop. ; Check @extended above if you want better error handling. ; The current option is stored in $GetOpt_Opt, it's index (in $GetOpt_Opts) ; in $GetOpt_Ind and it's value in $GetOpt_Arg. Switch $sOpt ; What is the current option? Case '?' ; Unknown options come here. @extended is set to $E_GETOPT_UNKNOWN_OPTION $sMsg &= 'Unknown option: ' & $GetOpt_Ind & ': ' & $GetOpt_Opt $sMsg &= ' with value "' & $GetOpt_Arg & '" (' & VarGetType($GetOpt_Arg) & ').' & @CRLF Case ':' ; Options with missing required arguments come here. @extended is set to $E_GETOPT_MISSING_ARGUMENT $sMsg &= 'Missing required argument for option: ' & $GetOpt_Ind & ': ' & $GetOpt_Opt & @CRLF Case 'a', 'b', 'c', 'w', 'p', 'm' $sMsg &= 'Option ' & $GetOpt_Ind & ': ' & $GetOpt_Opt $sMsg &= ' with value "' & $GetOpt_Arg & '" (' & VarGetType($GetOpt_Arg) & ')' If $GETOPT_MOD_PLUS = $GetOpt_Mod Then $sMsg &= ' and invoked with plus modifier (+' & $GetOpt_Opt & ')' ElseIf $GETOPT_MOD_MINUS = $GetOpt_Mod Then $sMsg &= ' and invoked with minus modifier (/-' & $GetOpt_Opt & ')' EndIf $sMsg &= '.' & @CRLF Case 'r' $sMsg &= 'Option ' & $GetOpt_Ind & ': ' & $GetOpt_Opt $sMsg &= ' with required value "' & $GetOpt_Arg & '" (' & VarGetType($GetOpt_Arg) & ')' If $GETOPT_MOD_PLUS = $GetOpt_Mod Then $sMsg &= ' and invoked with plus modifier (+' & $GetOpt_Opt & ')' ElseIf $GETOPT_MOD_MINUS = $GetOpt_Mod Then $sMsg &= ' and invoked with minus modifier (/-' & $GetOpt_Opt & ')' EndIf $sMsg &= '.' & @CRLF Case 's' $sMsg &= 'Option ' & $GetOpt_Ind & ': ' & $GetOpt_Opt $sMsg &= ' with required suboptions:' & @CRLF While 1 ; Loop through suboptions. $sSubOpt = _GetOpt_Sub($GetOpt_Arg, $aSubOpts) If Not $sSubOpt Then ExitLoop ; No suboptions or end of loop. ; Check @extended above if you want better error handling. ; The current suboption is stored in $GetOpt_SubOpt, it's index (in $GetOpt_SubOpts) ; in $GetOpt_SubInd and it's value in $GetOpt_SubArg. Switch $sSubOpt ; What is the current suboption? Case '?' $sMsg &= ' Unknown suboption ' & $GetOpt_SubInd & ': ' & $GetOpt_SubOpt $sMsg &= ' with value "' & $GetOpt_SubArg & '" (' & VarGetType($GetOpt_SubArg) & ').' & @CRLF Case 'foo', 'bar' $sMsg &= ' Suboption ' & $GetOpt_SubInd & ': ' & $GetOpt_SubOpt $sMsg &= ' with value "' & $GetOpt_SubArg & '" (' & VarGetType($GetOpt_SubArg) & ').' & @CRLF EndSwitch WEnd If $GETOPT_MOD_PLUS = $GetOpt_Mod Then $sMsg &= 'And invoked with plus modifier (+' & $GetOpt_Opt & ').' ElseIf $GETOPT_MOD_MINUS = $GetOpt_Mod Then $sMsg &= ' and invoked with minus modifier (/-' & $GetOpt_Opt & ')' EndIf Case 'h' MsgBox(0, 'GetOpt.au3', 'GetOpt.au3 example.' & @CRLF & _ 'Just try out some options and find out what happens!') Exit EndSwitch WEnd Else $sMsg &= 'No options passed.' & @CRLF EndIf $sMsg &= @CRLF If 0 < $GetOpt_Opers[0] Then ; If there are any operands... While 1 ; ...loop through them one by one. $sOper = _GetOpt_Oper() ; Get the next operand. If Not $sOper Then ExitLoop ; no operands or end of loop. ; Check @extended above if you want better error handling. $sMsg &= 'Operand ' & $GetOpt_OperInd & ': ' & $sOper & @CRLF WEnd Else $sMsg &= 'No operands passed.' & @CRLF EndIf MsgBox(0, @ScriptName, $sMsg) ; Let's see what we've got. _ArrayDisplay($GetOpt_Opts, '$GetOpt_Opts') _ArrayDisplay($GetOpt_Opers, '$GetOpt_Opers') _ArrayDisplay($GetOpt_ArgV, '$GetOpt_ArgV') Exit EndFunc Version 1.3: + Added support for -- (marks end of options). + Added support for + option modifiers e.g. +x. + Added support for /- option modifiers e.g. /-X. + Added _GetOpt_Sub to iterate through comma-separated suboptions like -s=a=foo,b=bar. * Changed $GETOPT_REQUIRED_ARGUMENT from keyword Default to Chr(127), keyword can now be used as an option argument. * Standardized comments and function headers. * Tidy-ed up source code. Version 1.2: + Support for required arguments with options, e.g. _GetOpt('ab:c') where -b=foo is valid and -b will return an error. + Added support for /C:foo (colon) when using DOS style. + Added optional auto-casting of arguments from Strings to AutoIt variants, e.g. -a=yes on the CLI would set the $GetOpt_Arg to True and not 'yes'. See __GetOpt_Cast. * Private __GetOpt_DOSToGNU to simplify code. Version 1.1: * Initial public release. If you encounter any bugs or have any suggestions, requests or improvements, then please let me know. Happy coding!
  2. Hi all, I need to read a log file into an array, but the log file is encoded as $FO_UTF16_BE_NOBOM (2048) = Use Unicode UTF16 Big Endian (without BOM) per FileGetEncoding (it returns 2048). I have searched how to convert these log files to UTF-8 and finally found a Powershell command. Since then I have been racking my brain trying to get the function to work. The command itself works from a Powerscript prompt: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command Get-Content C:\Logs\Myplayer_10-10-17-02-31.log | Set-Content -Encoding utf8 C:\Logs\Myplayer1.log This is my sandbox; #include <array.au3> #include <File.au3> Local $aArrayLogFile Local $sLogDir = "C:\Logs\" Local $sLogFile = "Myplayer_10-10-17-02-31.log" Local $sConvertedLog = "ConvertedLog.log" Local $sLogDirFile = $sLogDir&$sLogFile RunWait("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command Get-Content "&$sLogDirFile&" | Set-Content -Encoding utf8 "&$sConvertedLog,$sLogDir) _FileReadToArray($sLogDirFile, $aArrayLogFile) _ArrayDisplay($aArrayLogFile) Also tried RunWait("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command Get-Content "&$sLogDirFile&" | Set-Content -Encoding utf8 "&$sConvertedLog,$sLogDir) and ShellExecuteWait("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"," -Command Get-Content "&$sLogDirFile&" | Set-Content -Encoding utf8 "&$sConvertedLog,$sLogDir) Tried without -Command and a bunch of other parameters that were sprinkled throughout the internet from people trying to get this to work. Thanks Jibs
  3. Greetings, I need write a command line to run an .exe with parameters, one this parameters is a password with special characters like: [ ] \ " etc. The password is write between double cotes too. When run this command line, catch error. I buid this function, sometimes run ok, others show error. Someone can any idea? Best ragards #include <Array.au3> Global $G_AIX_DEFAULT_PASSWORD = "******" Func Scape_Word_To_MSDOS($var = "") ;~ https://www.robvanderwoude.com/escapechars.php Local $aCharacters[][2] = [ _ ["%", "%%"], _ ["^", "^^"], _ ["&", "^&"], _ ["<", "^<"], _ [">", "^>"], _ ["|", "^|"], _ ["'", "^'"], _ ["`", "^`"], _ [",", "^,"], _ [";", "^;"], _ ["=", "^="], _ ["(", "^("], _ [")", "^)"], _ ["!", "^^!"], _ ["\", "\\"], _ ["[", "\["], _ ["]", "\]"], _ ['"', '\"""'], _ [".", "\."], _ ["*", "\*"], _ ["?", "\?"] _ ] Local $iSearch $var = StringSplit($var, "", $STR_NOCOUNT) Local $iSize = UBound($var, $UBOUND_ROWS) - 1 For $ii = 0 To $iSize $iSearch = _ArraySearch($aCharacters, $var[$ii]) If $iSearch >= 0 Then $var[$ii] = $aCharacters[$iSearch][1] Next Return _ArrayToString($var, "") EndFunc ;==>Scape_Word_To_MSDOS Local $password = "-Dk5iFB2UjOt[-x|""" & "" Local $password_scape = Scape_Word_To_MSDOS($password) ConsoleWrite("[" & $password & "]" & @LF) ConsoleWrite("[" & $password_scape & "]" & @LF)
  4. Greetings, I would like to be able to write a script to send commands to the console for creation of Gstreamer pipelines. I was thinking of something similar to this: Local $iPID = Run("C:\Windows\System32\cmd", "", @SW_MAXIMIZE) ;THIS OPENS THE CONSOLE...!!! if $iPID == 0 Then ConsoleWrite(@CRLF & "I DID NOT OPEN CMD...error: " & @error & @CRLF) if $iPID <> 0 Then ConsoleWrite(@CRLF & "I OPENED CMD...!!!" & @CRLF) $hCmd = WinGetHandle("C:\WINDOWS\system32\cmd.exe") if $hCmd <> 0 Then WinActivate($hCmd) ;ensure command console is active... $sOutput = Send("cd C:\gstreamer\1.0\x86_64\bin" & @CRLF, $SEND_RAW) $sOutput = Send("gst-launch-1.0 videotestsrc ! autovideosink" & @CRLF, $SEND_RAW) Sleep(3000) ControlSend($hCmd, "", "", "exit" & @CR) EndIf ;$hCmd NOT "0"... I don't really know if this is the best way to open the console and send commands into it. I'm also not sure about how to best catch any errors that may occur...likely this needs to be accomplished with the STDOUTREAD command however I've not had experience using it before and therefore would appreciate some advice that anybody may offer. Basically I'm seeking guidance on how to best automate the opening of the console, sending lines of commands to be executed, and handling any potential errors in the execution of those commands...I thank you in advance. Regards.
  5. I use a program called Screenpresso. It can run a command that captures the screen from certain coordinates. I would like to be able to capture the mouse coordinates and then fill them in my command. The normal command looks like this. screenpresso.exe -captureregion "D:\Test\test2.jpg" 0;0;1280;720 It is at 0;0 where I would like to insert the mouse coordinates. Can someone show me how to do this with AutoIt Thanks
  6. I am Very new to Autoit and I'm trying to figure out how to input text in an administrator Level Command prompt on windows 10. this is what I currently have Send ("#r") WinWaitActive("Run") Send("runas /user:Administrator cmd") Send("{Enter}") WinWait("C:\WINDOWS\system32\runas.exe") ControlClick("", "", "[CLASS:ConsoleWindowClass]") Send("test-Password") Send("{Enter}") The issue I am having is I can not send the "test-password" to the command prompt. I cried adding the ControlClick command to place the cursor in he CMD box, but its still not working. What am I doing wrong?
  7. autoit3 under Win7 (x64) Here's a very simple script that reports the number of parameters it's called with: cmd_line_nparm.au3 $nparm = $CmdLine[0] ; number of parameters MsgBox(0,"","nparm: " & $nparm) If I start a dos session and cd to the folder where this file is stored and run cmd_line_nparm.au3 abc def the response is nparm: 0 ; but if I provide the full path to the autoit exe file I get the correct answer (2). Can anyone tell me what I need to do to avoid having to provide the full path? (Hopefully without needing to re-install autoit3) Thanks!
  8. I can run this and notepad++ opens the file Run("C:\Program Files (x86)\Notepad++\notepad++.exe E:\icare\icare\NI-WI-NBSE-ERR.xml") But what I want is to run the .au3 or exe from command line and send it the file as parameter -am I being to simplistic in hoping its this easy? #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #include <File.au3> ;E:\icare\icare\NI-WI-NBSE-ERR.xml ;Run("C:\Program Files (x86)\Notepad++\notepad++.exe E:\icare\icare\NI-WI-NBSE-ERR.xml") Run("C:\Program Files (x86)\Notepad++\notepad++.exe " & $CmdLine[0] ) sleep (200) Send("{CTRLDOWN}a{CTRLUP}") sleep (500) Send("{CTRLDOWN}a{CTRLUP}{CTRLDOWN}s{CTRLUP}{CTRLDOWN}{SHIFTDOWN}b{CTRLUP}{SHIFTUP}") sleep (500) Send("{CTRLDOWN}{ALTDOWN}s{ALTUP}{CTRLUP}") sleep (500) Send("E:\icare\icare\NI_WI_MONTHLY_INSTALMENTS_c2base64-7.txt") sleep (500) Send("{ENTER}")
  9. How do I make this variable work? $MY_SESSION_ID = for /f "tokens=3-4" %%a in ('query session %username%') do @if "%%b"=="Active" set MY_SESSION_ID=%%a MsgBox(1, "My Session ID", "Session ID is: " & $MY_SESSION_ID)
  10. ShellExecute("\\servername\cofs\Organization\ITS\_Software & Hardware\AS400\DVD\Windows\cwblaunch.exe", '"/v/qn ADDLOCAL=ALL"') I had to dig to find the right setup.exe according to the documentation but I got it to run. However, it pops up with this dialog box (attached) showing me the command line parameters, as if I'm incorrect. It continues to run the install however, but seemingly without any of the command line parameters. Here's the command I entered into the CMD prompt exactly: "\\servername\cofs\Organization\ITS\_Software & Hardware\AS400\DVD\Windows\image64a\setup.exe",'"/v/qn ADDLOCAL=ALL"'
  11. I feel like i have been going in circles and getting no where I am trying to do a git pull LOCAL $sTemp = '"C:\Program Files (x86)\Git\bin\git.exe" pull' LOCAL $sLine = '' local $sToWrite = '' local $PID = Run($sTemp,$GitDir,@SW_MAXIMIZE, $STDIN_CHILD + $STDOUT_CHILD) StdinWrite($PID,$sToWrite) IF( $PID <> 0) THEN While 1 $sLine &= StdoutRead($PID) MsgBox(0,'returned',$sLine) If @error Then ExitLoop Sleep(25) Wend Exit EndIf i have also tried LOCAL $sTemp = '"C:\Program Files (x86)\Git\bin\git.exe" pull' LOCAL $sLine = '' local $PID = Run($sTemp,$GitDir,@SW_MAXIMIZE, $STDIN_CHILD + $STDOUT_CHILD) StdinWrite($PID) IF( $PID <> 0) THEN While 1 $sLine &= StdoutRead($PID) MsgBox(0,'returned',$sLine) If @error Then ExitLoop Sleep(25) Wend Exit EndIf This triggers the command prompt which gives me this info eventually Username for 'SomeNonGitHubRepositiory': Problem is that My message box always returns a blank without erroring out If it did return somethign then i would do $sToWrite = 'Username' StdinWrite($PID,$sToWrite) What did i miss?
  12. Hi Everyone I want to have a GUI, but which will accept command line options on launch. So, the commanline would look something like myAPP.EXE -bigfont -bigicon where myAPP.EXE would be the name of the AutoIt EXE, and the -bigfont & -bigicon items represent optional command line parameters with which the EXE starts. I am not looking at creating a CUI. This is GUI, but with startup command line parameters. These command line parameters would only be read once, during start up of the EXE. I have searched the forum, no luck. What I did find was this commented by Water: https://www.autoitscript.com/forum/topic/138754-adding-command-line-parameter/ Should I start the GUI EXE as normal, and then first possible opportunity read the command line? Is that the way to go? Thanks in advance
  13. I am trying to create a script that allows me to run and use it with CMD as the interface. For example: This is the code I have so far... #AutoIt3Wrapper_Change2CUI=y ConsoleWrite("Enter PIN" & @CRLF & ":") Local $input While 1 $input &= ConsoleRead() if StringInStr($input,@CRLF) <> 0 then ExitLoop Wend if $input = "1111" & @CRLF Then ConsoleWrite("Success") Else ConsoleWrite("Failure") ConsoleWrite($input) EndIf The problem is that after it writes Enter PIN: it will not accept input and gets stuck. After I close the script, all the input I typed shows up in cmd. I want be able to run this script without opening another cmd window but I haven't been able to find relevant examples for creating a "console" application used through cmd. Can anyone help me out?
  14. I forgot to update this, I had responded to a topic with an updated PCRE for parsing individual items/options, so here's the updated code: _StringParseParameters: Parse Parameters in a string: Returns an array as if a command-line parser split the elements, or if nothing found an @error. Note there is a look-behind and look-ahead assertion to prevent grabbing quotes, while also allowing for cases where there are empty quotes (""): Local $aParsedArray=StringRegExp($sStringToParse,'((?<=\s"|^")[^"]+(?=")|[^\s"]+)',3) The only thing I'd do beforehand is expand any environment strings like %windir%. All you'd need for that is to just set the "ExpandEnvStrings" option, assign the string to itself (looks dumb, but accomplishes the needed expansion), then reset the option. (or call the ExpandEnvironmentStrings API function) The old version of this can still be found in a post I had made in the thread ' - it also parses comma-separated arguments, though retaining quotes. That could easily be remedied though.
×
×
  • Create New...