How to pass CRLF in a parameter

Started by Jeremy Whilde, August 02, 2018, 09:36:10 AM

Previous topic - Next topic

Jeremy Whilde

How do you pass a carriage return line feed in a parameter? I have a compiled WinBatch script that sends some text to another application window and this needs to be supplied from command line parameters. But in the compiled version I cannot seem to pass the CRLF correctly whatever I do when it is compiled all I get displayed in the external application is a single line of text!

If I do the following inside the script and run it uncompiled then I can pass multiple lines of text with the CRLF correctly inserted and displayed in the external application window:

param1 = "text" ; Simulate sending param 1

crlf = StrCat(Num2Char(13), Num2Char(10))

param2 = "Line1%crlf%Line2" ; Simulate sending param 2

....The rest of the script ....

; Send the text

If Param1 == "text" then cSetWndText(Controlhandle, param2)


So this will display correctly as:

Line1
Line2


But when I compile the script  and  run it with parameters of text "Line1%crlf%Line2"

I get:

Line1%crlf%Line2


Any help greatly appreciated

Thanks, JW


td

If by "command line parameters" you are referring to launching a compiled script with a parameter from a shortcut or the Windows command shell, this is expected behavior.  Substitution is only performed on the lines within your script, not on the contents of variables.   Your command line parameter is not a line in your script it.  It is the content of a variable.   

You might want to consider using the StrReplace function on param1 in your script.
Code (winbatch) Select
if param0 then message('Command line', StrReplace(param1, '<crlf>', @crlf))
exit


Where the command line argument is something like "My command line parameter<crlf>has a carriage return and line feed"
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

Jeremy Whilde

OK yes, thank you the substitution explanation makes sense when considering the compiled executable receiving the parameters. So the following fixes the issue:

newText = StrReplace(param2, '<crlf>', @crlf)

If Param1 == "text" then cSetWndText(Controlhandle, newText)

Thanks, JW

notds

param2 = "Line1<crlf>Line2" ; Simulate sending param 2

newText = StrReplace(param2, '<crlf>', @crlf)

If Param1 == "text" then cSetWndText(Controlhandle, newText)

OR

Code (winbatch) Select


Param2 = "You could just do your" : @CRLF : "Next line like this" : @CRLF : "And your next line like this"

If Param1 == "text" then cSetWndText(Controlhandle, Param2)

;or

If Param1 == "text" then cSetWndText(Controlhandle, "You could just do your" : @CRLF : "Next line like this" : @CRLF : "And your next line like this")