Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have multiple problems in your modified check.bat</p> <p>The quotes are a state machine in that the 1st quote turns quoting semantics ON, the 2nd OFF, the 3rd ON, etc. An unquoted (and unescaped) <code>&gt;</code> is interpreted as an instruction to redirect output.</p> <p>I've heavily modified check.bat by putting in a bunch of ECHO statements to provide a narrative of what is happening. Your original code is embedded in my version as all CAPS.</p> <p>Here is the output of my modified version, which I hope explains why you are getting your results. I want you to read this output before you try to understand how my modified check.bat produces this output.</p> <pre><code>"a" --------------------------------------------- Executing: SET RAWINPUT=%1 which expands to SET RAWINPUT="a" Here is the result: rawinput="a" Executing: SET INPUT=%~1 which expands to SET INPUT=a Here is the result: input=a Executing: ECHO %1 which expands to ECHO "a" "a" Executing: ECHO "%RAWINIPUT%" which expands to ECHO ""a"" ""a"" Executing: ECHO "%INPUT%" which expands to ECHO "a" "a" "b -&gt; b" --------------------------------------------- Executing: SET RAWINPUT=%1 which expands to SET RAWINPUT="b -&gt; b" Here is the result: rawinput="b -&gt; b" Executing: SET INPUT=%~1 which expands to SET INPUT=b -&gt; b Here is the result: input=b - Also created a file named "b" because the output of the command is redirected. The file is empty because SET has no output. Volume in drive C is OS Volume Serial Number is EE2C-5A11 Directory of C:\Users\Public\utils 11/20/2012 09:30 AM 0 b 1 File(s) 0 bytes 0 Dir(s) 316,104,765,440 bytes free Executing: ECHO %1 which expands to ECHO "b -&gt; b" "b -&gt; b" Executing: ECHO "%RAWINIPUT%" which expands to ECHO ""b -&gt; b"" There is no screen output because output was redirected to file "b" Here are the contents of "b": ""b - Executing: ECHO "%INPUT%" which expands to ECHO "b -" "b -" </code></pre> <p>Here is my modified check.bat that produces the output above.</p> <pre><code>setlocal enableDelayedExpansion set value=%1 set "unquotedValue=%~1" echo --------------------------------------------- echo Executing: SET RAWINPUT=%%1 which expands to SET RAWINPUT=!value! SET RAWINPUT=%1 echo Here is the result: set rawinput echo. echo Executing: SET INPUT=%%~1 which expands to SET INPUT=!unquotedValue! SET INPUT=%~1 echo Here is the result: set input if exist b ( echo. echo Also created a file named "b" because the output of the command echo is redirected. The file is empty because SET has no output. echo. dir b del b ) echo. echo Executing: ECHO %%1 which expands to ECHO !value! ECHO %1 echo. echo Executing: ECHO "%%RAWINIPUT%%" which expands to ECHO "!rawinput!" ECHO "%RAWINPUT%" if exist b ( echo. echo There is no screen output because output was redirected to file "b" echo Here are the contents of "b": type b del b ) echo. echo Executing: ECHO "%%INPUT%%" which expands to ECHO "!input!" ECHO "%INPUT%" echo. </code></pre> <p><br/>You can get your desired results via a variable if you do not add any quotes in your check.bat</p> <pre><code>set rawinput=%1 echo %rawinput% </code></pre> <p>But all hell can break loose if your original text file includes its own quotes.</p> <p>That is the reason jeb suggests storing each line in a variable within your main routine and then pass the name of the variable to check.bat. Within check.bat you can use delayed expansion to safely work with any value without worrying about quotes or escapes.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload