Jump to content

Recommended Posts


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]

    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

Visit my repository

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 :


Good luck :)

Edited by pixelsearch
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.


My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By sg08234
      Members 0   2 10 posts   Posted 1 minute ago I have a littel script:
      AutoItSetOption("MustDeclareVars", 1) #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Local $iReturn  ; Returnwert Local $iVar     ; Variable Local $iBit     ; Bitnummer $iVar=$Cmdline[2] $iBit=$Cmdline[3] Switch $Cmdline[1]     Case 1         $iReturn=BitOr ($ivar,2^$iBit)     Case 2         $iReturn=BitAnd ($iVar,2^$iBit)         if ($iReturn = 2^$iBit ) Then             $iReturn=0         Else             $iReturn=1         EndIf EndSwitch Exit $iReturn which does bit handling. It works as desired but: If I want to check the Returncode of the EXE created in the calling batch within an if-clause %ERRORLEVEL% does not match the Returncode  of my script (calling outside of an if-clause works as desired).
      My assumption for this behaviour is: I do not use  enabledelayedexpansion  in my batch-system and thus this special "variable" %ERRORLEVEL% is not defined in the if-clause. If my assumption is correct: How can I retransfer the Returncode to batch?
      Thanks - Michael
    • By DannyJ
      I use _ClipPutHTML UDF function 
      My problem is that I am not able to write characters with accets.
      When I paste this code to an Mail program the accent characters will be Chinese characters or '???' characters.
      Here is a snippet of my code:
      #include <_ClipPutHTML.au3> $sHTMLStr='<html><head>'&@CRLF & " <title>Page Title</title>"&@CRLF & _ ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'&@CRLF & _ "</head>"&@CRLF & "<body>"&@CRLF & "<h1>Headline Text</h1>"&@CRLF & _ "<p>" & "ófiéááéllááéáéá:" & Chr(225) & BinaryToString("á",4) &@CRLF & _ '<a href="http://www.autoitscript.com/forum/index.php?showtopic=96556">_ClipPutHTML() functions</a>.'&@CRLF& _ " The regular modifiders, such as <strong>bold</strong>, <i>italics</i>, and <u>underlines</u> work as usual,"&@CRLF& _ " just like all other HTML formatting.</p>"&@CRLF & "<p>&nbsp;</p>"&@CRLF & _ "<p><strong>Here's an example list:</strong></p>"&@CRLF & "<ul>"&@CRLF & _ " <li>List <i>itemü</i> #1.</li>"&@CRLF & _ " <li>List <i>itemá</i> #2.</li>"&@CRLF & _ ' <li>List <i>itemé</i> #3 with a <a href="http://www.google.com">Hyperlink</a></li>'&@CRLF & _ "</ul>"&@CRLF & "</body>"&@CRLF & "</html>" $sPlainTextStr="Headline Text"&@CRLF&@CRLF& _ "ófigyeljáéáéá" & Chr(225) & "_ClipPutHTML() functions."& _ "The regular modifiders, such as bold, italics, and underlines work as usual, just like all other HTML formatting."&@CRLF&@CRLF& _ "Here's an example list:"&@CRLF& _ " * List itemü #1."&@CRLF& _ " * List itemá #2."&@CRLF& _ " * List itemé #3 with a Hyperlink"&@CRLF ;I have tired this way, but it does not work. ;$UTF8HTML = BinaryToString($sHTMLStr,4) ;ConsoleWrite($UTF8HTML) ;$sUTF8String=BinaryToString($sPlainTextStr,4) ConsoleWrite($sUTF8String) _ClipPutHTML($UTF8HTML,$sUTF8String) ; Special Unicode text call ;_ClipPutHyperlink("http://www.google.co.jp/",ChrW(0x30B0)& ChrW(0x30FC)& ChrW(0x30B0)& ChrW(0x30EB)& " (Japanese Google)") ; Regular text ;_ClipPutHyperlink("http://www.google.com","itt")  
    • 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.5.zip  (MAJOR UPDATE - see detail at Post #39)
      P.S. I am not affiliated in any way with those who created and provide the excellent third party program - TeraCopy.
    • By Burgs
        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
  • Create New...