user3108268
user3108268

Reputation: 1083

Pass Windows batch variables with spaces in FroG GUI?

FroG helps you build a GUI for your Windows batch (.bat) file, based on XML.

E.g. set three variables and print to text file, so .bat looks like this:

@echo off &setlocal

setlocal EnableDelayedExpansion

set var1=%1
shift
set var2=%1
shift
set var3=%1

echo %var1% %var2% %var3%> test.txt

(As I understand you have to pass shift to make FroG catch up after variables? I can't make it work in any other way, I took this from some sample built on FroG)

GUI code looks like this:

<form caption="test GUI" program="test.bat" icon="" showconsole="false" width="514" url="" description="" author="">
    <control type="tabset">
        <tabsheet caption="General" active="true">
            <control type="groupbox" caption=" Basic info " fontstyle="bold">
                <control type="edit" caption=" Variable 1 " commandline="" width="100"/>
                <control type="edit" caption=" Variable 2 " commandline="" width="100"/>
                <control type="edit" caption=" Variable 3 " commandline="" width="100"/>
            </control>
        </tabsheet>
    </control>
</form >

And GUI interface looks like this: enter image description here

(the values entered in the three fields gets passed to the bottom line test.bat ..., the way I see it, the shift ignores that last variable has a space and prints only three, so the bottom line three four must be in quotes, but if you add quotes manually, they also get printed into the file, which we do not want, see paragraph 4 below)

As you can see we already have values set, var1 is 'one', var2 is 'two' and var3 contains a space and is 'three four'.

  1. After clicking Execute the output in my test.txt is one two three. But it is missing the 'four' from var3.

  2. Now I tried wrapping my vars in the .bat like e.g. set "var3=%1" but get same result.

  3. Or set var3="%1" but it prints 'three' with quotes one two "three" still no 'four'.

  4. And I tried entering in the GUI 'three four' with quotes like "three four" and it prints the 'four' part, but it's wrong because it prints with the quotes we just entered and we don't want that one two "three four".

Expected result should be one two three four with spaces and no quotes.

Update

Did some more testing and found out we can achieve same without shift, but like this:

set var1=%1
set var2=%2
set var3=%3

Same issue still persists, printed on cli or to file, it skips the last string if the variable is not in quotes on the GUI, but if it is, then it prints the quotes too.

TLDR: Need to pass a string with quotes (because of spaces in the string) in the GUI, but not print the quotes.

Upvotes: 2

Views: 382

Answers (1)

Compo
Compo

Reputation: 38718

I have tested it without problems, just use the examples below!

test.cmd

@Echo Off

Set "var1=%~1"
Set "var2=%~2"
Set "var3=%~3"

If "%~3"=="" Exit /B
(Echo=%var1% %var2% %var3%)>"test.txt"

test.frontend

<form caption="test GUI" program="test.cmd" icon="" showconsole="false" width="514" url="" description="" author="">
    <control type="tabset">
        <tabsheet caption="General" active="true">
            <control type="groupbox" caption=" Basic info " fontstyle="bold">
                <control type="edit" caption=" Variable 1 " commandline="" width="100"/>
                <control type="edit" caption=" Variable 2 " commandline="" width="100"/>
                <control type="edit" caption=" Variable 3 " commandline="" width="100"/>
            </control>
        </tabsheet>
    </control>
</form >

screenshot

enter image description here

test.txt

one two three four

Upvotes: 1

Related Questions