Jump to content

Need help with sending "{" (squiggly brackets) into a RUN command


Recommended Posts

Hi all there.

I'm a semi-new to AutoIT ... I've used it for a few simple things before (essentially making binaries out of batch'ed operations), but have run into a bit of a problem now.

I need to pass on a GUID-like string (with the whole squiggly brackets thing) as a part of a command-line parameter for RUN.

I've tried using various sorts of trickery - using variables to define the string, trying to use the syntax from SEND ... but it doesn't want to work for me.

The command I need to end up sending with is essentially of this sort:

""

MyBinary.exe /some_Parameters {1234-1234-1234-1234}

""

and the "{}"-s are killing me. I'm sure I'm missing something daft ... can't figure out what though. I've trawled through the forums and it doesn't seem like anyone's run into this (so either I'm being a special sort of plank, or it's just a pain in the rear to search for "{" as part of a search string) :D.

Thanks for any help.

Link to comment
Share on other sites

Send ( "keys" [, flag] )

[optional] Changes how "keys" is processed:

flag = 0 (default), Text contains special characters like + and ! to indicate SHIFT and ALT key-presses.

flag = 1, keys are sent raw.

Try send("MyBinary.exe /some_Parameters {1234-1234-1234-1234}",1)

Link to comment
Share on other sites

Send ( "keys" [, flag] )

[optional] Changes how "keys" is processed:

flag = 0 (default), Text contains special characters like + and ! to indicate SHIFT and ALT key-presses.

flag = 1, keys are sent raw.

Try send("MyBinary.exe /some_Parameters {1234-1234-1234-1234}",1)

It's not "Send" that I'm using - sorry, it's Run, as I need to keep things as invisible to the user as possible (I'm doing some other stuff with mapping drives + usernames/passwords in the script too, so if it's at all possible, I'd prefer to use RUN as opposed to SEND. I'd prefer not to have a CMD-box open where the user would see this happening - hence my beating my head against RUN's wall as it were :D.

If that's not doable with RUN, then the confirmation will be a start (and I'll need to figure out how else I can get this done) :o.

Thanks so far.

Edited by Shathal
Link to comment
Share on other sites

It's not "Send" that I'm using - sorry, it's Run, as I need to keep things as invisible to the user as possible (I'm doing some other stuff with mapping drives + usernames/passwords in the script too, so if it's at all possible, I'd prefer to use RUN as opposed to SEND. I'd prefer not to have a CMD-box open where the user would see this happening - hence my beating my head against RUN's wall as it were :D.

If that's not doable with RUN, then the confirmation will be a start (and I'll need to figure out how else I can get this done) :o.

Thanks so far.

$GUID = '{1234-1234-1234-1234}'

MyBinary.exe /some_Parameters & " " & $GUID

Link to comment
Share on other sites

$GUID = '{1234-1234-1234-1234}'

MyBinary.exe /some_Parameters & " " & $GUID

I shall give that a try ... last I compiled something like this earlier on today, AutoIT barfed out on me, but maybe that's because something was missing...

Thanks.

Link to comment
Share on other sites

$GUID = '{1234-1234-1234-1234}'

MyBinary.exe /some_Parameters & " " & $GUID

Nope - still doesn't seem to work for me :D.

I've tried checking whether it was a syntax thing by changing it to:

""

Run("echo " & $GUID & " > c:\output.txt")

""

to see in a crude way if this would get passed, but no such luck :o.

Edited by Shathal
Link to comment
Share on other sites

See if this works for you...

$LeftBrace = Chr(123)
$RightBrace = Chr(125)

$GUID = $LeftBrace & "1234-1234-1234-1234" & $RightBrace

MsgBox(0,"",$GUID)

Nope - still doesn't seem to work for me :D.

I've tried checking whether it was a syntax thing by changing it to:

""

Run("echo " & $GUID & " > c:\output.txt")

""

to see in a crude way if this would get passed, but no such luck :o.

Link to comment
Share on other sites

Also keep in mind that a lot of times with the run command you need to include the $STDIN_CHILD etc parameters...

#include <Constants.au3>
; Example Usage
$result= _CMDreturn('MyBinary.exe /some_Parameters {1234-1234-1234-1234}')
msgbox(0,"Result",$result)


Func _CMDreturn($sCommand) ; This function returns the output of a DOS command as a string
    $cmdreturn = ""
    $stream = Run(@ComSpec & " /c " & $sCommand, @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD)
    While 1 ; loop through the return from the command until there is no more
        $line = StdoutRead($stream)
        If @error Then ExitLoop
        $cmdreturn &= $line
    WEnd
    Return $cmdreturn
EndFunc   ;==>_CMDreturn

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

See if this works for you...

$LeftBrace = Chr(123)
$RightBrace = Chr(125)

$GUID = $LeftBrace & "1234-1234-1234-1234" & $RightBrace

MsgBox(0,"",$GUID)
Hmm - that one unfortunately doesn't work - it really does seem that when RUN parses through a "{" it thinks it's an open bracket (since the MSGBOX and SEND functions seem to be able to cope quite OK by my jumping through one hoop or another).

(Again, I'm down to a simple

""

RUN ("echo Get this " & $GUID & " > c:\output.txt")

""

... to make sure that it "can" actually run ... but it seems that RUN falls flat on its face upon parsing a "{" :D.

Link to comment
Share on other sites

Also keep in mind that a lot of times with the run command you need to include the $STDIN_CHILD etc parameters...

#include <Constants.au3>
; Example Usage
$result= _CMDreturn('MyBinary.exe /some_Parameters {1234-1234-1234-1234}')
msgbox(0,"Result",$result)


Func _CMDreturn($sCommand) ; This function returns the output of a DOS command as a string
    $cmdreturn = ""
    $stream = Run(@ComSpec & " /c " & $sCommand, @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD)
    While 1 ; loop through the return from the command until there is no more
        $line = StdoutRead($stream)
        If @error Then ExitLoop
        $cmdreturn &= $line
    WEnd
    Return $cmdreturn
EndFunc   ;==>_CMDreturn
Aye - I thought that being a problem too, but if I do a:

""

Run("echo yadda yadda yadda > c:\output.txt")

""

this works (equally, it works as long as I add string-pieces carefully - it only barfs out when the {}-s come in to it.

Would this qualify as a bug (trying to figure out if it's a bug or just working as (unfortunately) designed)?

Link to comment
Share on other sites

This sure looks like its passing along the {} propperly to me...

#include <Constants.au3>

; Example Usage

$result = _CMDreturn('echo a line with {something} in curly brackets')
MsgBox(0, "Result", $result)

Func _CMDreturn($sCommand) ; This function returns the output of a DOS command as a string
    $cmdreturn = ""
    $stream = Run(@ComSpec & " /c " & $sCommand, @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD)
    While 1 ; loop through the return from the command until there is no more
        $line = StdoutRead($stream)
        If @error Then ExitLoop
        $cmdreturn &= $line
    WEnd
    Return $cmdreturn
EndFunc   ;==>_CMDreturn

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

There's nothing that should stop it from being passed. I just ran a simple test of Run("cmd /k echo {apple}") and in the window, I saw that the { } were passed correctly.

Have you tried using a different computer to see if the error is local?

Hmmm ... adding "cmd /c" in front of my command does seem to fix this ... strange. With that, my Echo works.

Not quite sure why "cmd /c" should make a difference here but ... let me rework my script to use CMD /C in front ... if this works, this would make my life a lot easier indeed :D

Great detail (I hope) :o.

Link to comment
Share on other sites

There's nothing that should stop it from being passed. I just ran a simple test of Run("cmd /k echo {apple}") and in the window, I saw that the { } were passed correctly.

Have you tried using a different computer to see if the error is local?

*scratches head*

This is strange ...

So - adding "cmd /c" does seem to have helped along - if I use the "cmd /c echo " & "cmd /c (command line building)" & " > c:\output.txt" approach, then I *do* get the correct command-line printed into notepad.

So far so good :o ...

... however, removing the "cmd/ c echo" stuff (so as to run the actual command) - barfs out somewhere. Strange ... very strange ...

*more debugging*

AHA! A sneaky space problem (lack of space between two parameters.

Cool - this works - woohoo! THANKS :D

So "CMD /C" (for some reason) fixed this. Thanks! :D

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...