Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <code>for</code> loop you have there executes that script and runs for every line the script returns. Basically this means that your environment variable <code>%ScriptOut%</code> contains only the <em>last</em> line of the output (since it gets overwritten each time the loop processes another line). So if your script returns</p> <pre><code>a b c </code></pre> <p>then <code>%ScriptOut%</code> will contain only <code>c</code>. If the last line is empty or contains only spaces iot will effectively delete <code>%ScriptOut%</code> which is why when you do an</p> <pre><code>echo %ScriptOut% </code></pre> <p>you'll only get <code>ECHO is on.</code> since after variable substition all that's left there is <code>echo</code>. You can use</p> <p>echo.%ScriptOut%</p> <p>in which case you'll be getting an empty line (which would be what <code>%ScriptOut%</code> contains at that point.</p> <p>If you want to print every line the script returns to a file then you can do that much easier by simply doing a</p> <pre><code>cscript C:\MyProj\Sources\SearchString.vbs &gt; C:\ThreePartition\Sources\myfile.txt </code></pre> <p>or use <code>&gt;&gt;</code> for redirection if you want the output to be appended to the file, as <a href="https://stackoverflow.com/questions/737098/return-a-value-from-batch-files-bat-fileto-a-text-file/737146#737146">Stanislav Kniazev pointed out</a>.</p> <p>If you just want to store the last <em>non-empty</em> line, then the following might work:</p> <pre><code>for /f "delims=" %%a in ('C:\MyProj\Sources\SearchString.vbs') do ( if not "%%a"=="" set ScriptOut=%%a ) </code></pre> <p>which will only set <code>%ScriptOut%</code> in case the loop variable isn't empty.</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