Shathal Posted March 26, 2009 Posted March 26, 2009 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) . Thanks for any help.
KaFu Posted March 26, 2009 Posted March 26, 2009 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) OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Shathal Posted March 26, 2009 Author Posted March 26, 2009 (edited) 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 . 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) . Thanks so far. Edited March 26, 2009 by Shathal
czervika Posted March 26, 2009 Posted March 26, 2009 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 .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) .Thanks so far.$GUID = '{1234-1234-1234-1234}'MyBinary.exe /some_Parameters & " " & $GUID
Shathal Posted March 26, 2009 Author Posted March 26, 2009 $GUID = '{1234-1234-1234-1234}'MyBinary.exe /some_Parameters & " " & $GUIDI 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.
Shathal Posted March 26, 2009 Author Posted March 26, 2009 (edited) $GUID = '{1234-1234-1234-1234}'MyBinary.exe /some_Parameters & " " & $GUIDNope - still doesn't seem to work for me .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 . Edited March 26, 2009 by Shathal
erik7426 Posted March 26, 2009 Posted March 26, 2009 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 . 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 .
Richard Robertson Posted March 26, 2009 Posted March 26, 2009 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?
SpookMeister Posted March 26, 2009 Posted March 26, 2009 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]
Shathal Posted March 26, 2009 Author Posted March 26, 2009 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 "{" .
Shathal Posted March 26, 2009 Author Posted March 26, 2009 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)?
SpookMeister Posted March 26, 2009 Posted March 26, 2009 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]
Shathal Posted March 26, 2009 Author Posted March 26, 2009 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 Great detail (I hope) .
Shathal Posted March 26, 2009 Author Posted March 26, 2009 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 ...... 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 So "CMD /C" (for some reason) fixed this. Thanks!
Richard Robertson Posted March 26, 2009 Posted March 26, 2009 No, I used the parameter to make the cmd window visible after echo was run. It has nothing to do with it working or not working.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now