Jump to content
Skysnake

[Resolved] Command Line with <> param fails

Recommended Posts

Skysnake

Hi

Problem is this

myscript -p <zumerkelen> -x something else

myscript is my AutoIt compiled CUI.  

-p <> is first param - fails, see below

-x [text] second param, works.

When I run this with the param enclosed in <> I get the response

The syntax of the command is incorrect.

Experimentation indicates that the <> tags are the problem.

_ArrayDisplay($CmdLine, "1 Array")
MsgBox(16, "1 Raw", $CmdLineRaw)

The problem is with the reading of the command line.  It fails BEFORE it gets into the variables... :(

cmdFail.png

I am not dealing with AutoIt, or even my own command line, this is legacy software.  It seems that AutoIt "interprets" the <> before loading the command line...  I need to be able to read that as text without it being interpreted.

The only part I can control is my script, the myscript, which I can change at will.

The standard command line functions appear all to interpret params on read.  I want those params read raw.   If I could just get that as a string it would be fine.

Where to look?

Skysnake

 

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites
water

I assume that cmd.exe interprets <> as redirection operators. Can you test using quotes?

Quote

myscript -i "<myscript>"

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Skysnake

Hi Water :)

Ironic that you would be first on the scene.

I can test.  But problem is that I cannot change the received command line.  I receive it from legacy software which includes multiple <> instances... :(

 


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites
water

Do you really need the brackets? If the parameter contains spaces you could simply use quotes:

Quote

myscript -i "my script"


Edit: Answered by the post above

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Skysnake

Tested

cmdfail2.png


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites
Skysnake

I do not generate that command line and I cannot change it.  All I can do is read it.  And the standard AutoIt "command line read" apparently involves interpreting first...

 

Maybe a more specific question --- is that $CmdLineRaw part of the core AutoIt interpreter? Does this problem require developer intervention?

See this

Quote

Command Line Parameters

Passing command line parameters to your own executable is achievable in AutoIt. Passed commandline parameters can be viewed by using the constant variables $CmdLine and $CmdLineRaw. Assigning these variables with new data will cause AutoIt to return an error, as these cannot be changed during the script's execution. Note that both variables exist whether commandline parameters are passed or not.

 

From https://www.autoitscript.com/autoit3/docs/intro/running.htm

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites
water

The problem is caused by th way your legacy software calls your compiled script.
Compile both main.au3 and test.au3 and run main.exe.

; main.au3
Run("test.exe -i <Test>")
; Test.au3
#include <Array.au3>
_Arraydisplay($Cmdline)
msgbox(0, "", $Cmdlineraw)

You will see that you get the expected results.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water
18 minutes ago, Skysnake said:

Maybe a more specific question --- is that $CmdLineRaw part of the core AutoIt interpreter? Does this problem require developer intervention?

Yes and No.
Yes: $CmdLineRaw is part of AutoIt.
No: The error message you see is not generated by AutoIt but by the Windows command line interpreter (see post #2)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Skysnake

cmdfail3.png


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites
Skysnake

You have given me an idea.  I am going to check something. Thank you for your help. :)

Got it :)

Part of the problem is the documentation of the legacy software. The documentation indicates the use of <>, which the actual software does not use... So I was testing for something that does not exist.

Replaced the vendor app with my test script and it works like a charm.  I was in a corner there, but thank you for a clear head. :)

 

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites
water

:) 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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

    • jsmcpn
      By jsmcpn
      Hello all!  I'm trying to make a little script that sends a message over TCP.  An example payload would be:
      MY_PAYLOAD#<ATTRS><ATTR><NAME>MAILSERVER</NAME><OPERATION>set_value(ServiceStatus)</OPERATION><VALUE><![CDATA["Not Running"]]></VALUE><TIMESTAMP>1349297031</TIMESTAMP></ATTR></ATTRS> Note how the payload contains special characters, and how the CDATA contains a SPACE (i.e.  "Not Running")
      My compiled AU3 script expects exactly two command line arguments:
      1) destination server/port expressed as 127.0.0.1:80
      2) the payload I want to send to my server application (which may have multiple ATTRs, this example only has one ATTR)
      MyApp.exe 127.0.0.1:80 "MY_PAYLOAD#<ATTRS><ATTR><NAME>MAILSERVER</NAME><OPERATION>set_value(ServiceStatus)</OPERATION><VALUE><![CDATA["Not Running"]]></VALUE><TIMESTAMP>1349297031</TIMESTAMP></ATTR></ATTRS>"  
      My problems (plural) are with parsing of the second argument:
      1)  If I don't wrap second argument in double-quotes, then Windows bails out before even launching EXE with "< was unexpected at this time"
      2)  If I DO wrap second argument in double-quotes, then two problems can arise when my EXE parses the arguments:
                   aa) The double-quotes are stripped from the CDATA value. ["Running"] is stored in the array as [Running]
                   bb) If CDATA value DOES have a space, such as ["Not Running"], then I get an extra unwanted $CmdLine[3] because the SPACE between Not and Running is treated as a separator.  My second argument is thus split into two separate arguments, [2] and [3] instead of being treated as one arg stored in [2]
                              cc) Additionally, my script exits because it has an "IF $CmdLine[0] <>2 THEN Exit (1)" to validate the command line args.
      I've tried launching the EXE with the second argument wrapped and escaped in a multitude of ways.  Double double-quotes, triple double-quotes, single-quotes on the outside with double-quotes inside (i.e.  '"ETC"'), starting the second arg with a caret (i.e. ^"ETC") and one of three things happens:
      1) "< was unexpected at this time"
      2) my CDATA value is stripped of its double-quotes
      3) my payload argument gets split at the space in the CDATA value and the script bails out due to the unexpected 3rd argument.
       
      Any ideas?  How can I preserve the second argument literally, including all special characters, quotes and spaces?
      I tried adding some string manipulation code to grab the 2nd argument from $CmdLineRaw and it works (preserves the "Not Running" with quotes), but my number of arguments is still 3 instead of 2 if there is a space in the CDATA value.
       
      Any assistance would be greatly appreciated!
    • Chris86
    • jazzyjeff
      By jazzyjeff
      Hello,

      I am trying to understand the $CmdLine array. My goal is to run scriptA.exe have it create a variable $varA and then run scriptB.exe and have scriptB.exe output $varA to a Msgbox. It isn't working though, so I am not getting how this works.

      This is what I am trying:
      ScriptA -

      $varA = 'Test' Run('d:\(x86)\AutoIt3\AutoIt3.exe "D:\AutoIT Script\CMDLINE\scriptB.au3"') ScriptB -

      If $CmdLine[0] = 0 Then MsgBox(64, "Result", "No variable was found.") Else MsgBox(64, "Variable", $CmdLine[1] & $varA) EndIf
      If someone can help me understand why this isn't working, I'd appreciate it.
×