Jump to content

Recommended Posts

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)

 

 

Edited by Luigi

Share this post


Link to post
Share on other sites
Just now, Luigi said:

The password is written between double quotes too.

Hi Luigi
Could the error happen when the password includes an odd number of double-quotes in it ?

Another thought : Many times, within Run(), using chr(34) [which corresponds to the Ascii code of the double-quote] instead of the double-quote character itself (") makes it work in an easier way, so try to use them as much as you can within the Run command, instead of double-quotes. Those quotes & double-quotes are a real headache (especially when intermingled in a complex Run Command)

Here is an example where I use them :

Local $par1 = "1st par (variable)", $par2 = 2

$iPID = Run(@AutoItExe & " /AutoIt3ExecuteScript " & chr(34) & @ScriptDir & "\Run 1b.au3" & chr(34) & _
    " " & chr(34) & $par1 & chr(34) & _
    " " & $par2 & _
    " " & "3" & _
    " " & chr(34) & "4th par (string)" & chr(34))

which displays this in Run 1b.au3 :

146583910_Run1b.png.6f7fcd60444f5e96f49bc74a75c59f9a.png

Good luck :)

Edited by pixelsearch

Share this post


Link to post
Share on other sites

pixelsearch's method works great. I tend to think it looks cleaner to use single quotes, but it's personal preference

Local $par1 = '1st par (variable)', $par2 = 2

$iPID = Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptDir & '\Run 1b.au3"' & _
    ' "' & $par1 & '"' & _
    ' '  & $par2 & _
    ' '  & '3'   & _
    ' "4th par (string)"')

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By TheSaint
      TeraCopy Timer - A program of mine, front end really, that I have been working on (on & off) for some time, but not shared here before, that I recall. Third party program TeraCopy is required.
      Many of you will be familiar with TeraCopy, and it has been discussed here at AF on several occasions, in various sub forums, including Chat.
      BE ADVISED - I still use an older version of TeraCopy (v2.27), a goody but an oldy, so have only tested my program with that. It may work with the newer v3.xx, or may be easily adjusted to do so, but I have not yet gone that route. Likewise, I only use it with Win 7 and Win XP, but I don't imagine there should be any issues with newer Windows. Add to that, my program being devised and created in AutoIt v3.3.0.0.
      So what is TeraCopy Timer and why might you need it?
      --------------------------------------------------------------------------------------
      Those familiar with TeraCopy use, know you can run multiple copy or move jobs either simultaneously or concurrently (one immediately after another has finished). With the free version at least, you have no control over precise order or timing, and no way to deal (without manual interaction) with the pesky Thumbs.db files in Win XP. TeraCopy Timer allows you to do all those things, and in a batch fashion.
      --------------------------------------------------------------------------------------
      Some screenshots and brief explanation
      Main Window
      Minimalist Window
      This new WAIT feature is the simplest and best way to use the program generally (in my view) ... but check out the following, as it is not always the case.
      Advanced Delay Window
      WARNING - It should go without saying, that you take all the usual precautions. For instance, don't use move with the only copy you have of precious files. BACKUP BACKUP BACKUP! Don't hold me liable for anything, except for being a nice guy who likes to share.
      TeraCopy Timer v3.1.zip  (see detail at Post #37)
      Enjoy!
      OLDER DOWNLOADS
      P.S. I am not affiliated in any way with those who created and provide the excellent third party program - TeraCopy.
    • By Burgs
      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.
    • By pctechtv
      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
    • By vin1
      i have a script that selects  a text file and deletes a line (text input required) in the text file selected
      i have to make it remove all lines found on a file i name, toRemoveLines.txt
      it has to remove lines from all text files found in a folder
      this is the script that has to be modified
      where it says "select file" it has to be "select folder"
      where it says "line text input" it has to be all lines from a text file
      #Include <File.au3> Global $success = False $file_name = FileOpenDialog("Select file", @ScriptDir, "All files (*.*)", 1+4) $line_text_input = InputBox("Line's text", "Line must contain following text:", "line contains this text") $file_count_lines = _FileCountLines($file_name) for $i = 0 to $file_count_lines $Lines_text_output = FileReadLine($file_name, $i) if StringInStr($Lines_text_output, $line_text_input) then _FileWriteToLine($file_name, $i, "", 1) $success = True ExitLoop EndIf Next if $success = True Then MsgBox(0, "Success", "Line has been deleted") Else MsgBox(0, "Failure", "Line wasn't found") EndIf  
    • By jacobestepp
      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?
×
×
  • Create New...