Jump to content

scape special characters in ms-dos


Luigi
 Share

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

Visit my repository

Link to comment
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
Link to comment
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.

Spoiler

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
InputBoxes - Simple Input boxes for various variable types

Link to comment
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
 Share

×
×
  • Create New...