WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: Jeremy Whilde on August 02, 2018, 09:36:10 AM

Title: How to pass CRLF in a parameter
Post by: Jeremy Whilde on August 02, 2018, 09:36:10 AM
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

Title: Re: How to pass CRLF in a parameter
Post by: td on August 02, 2018, 01:21:12 PM
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"
Title: Re: How to pass CRLF in a parameter
Post by: Jeremy Whilde on August 03, 2018, 03:02:21 AM
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
Title: Re: How to pass CRLF in a parameter
Post by: notds on August 22, 2018, 03:38:42 PM
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")