Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.msdos.batch.nt    |    Fun with Windows NT batch files    |    68,980 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 67,964 of 68,980    |
|    JJ to John Stockton    |
|    Re: Return value from a CScript call?    |
|    12 Nov 22 13:46:53    |
   
   From: jj4public@outlook.com   
      
   On Fri, 11 Nov 2022 15:35:57 -0800 (PST), John Stockton wrote:   
   > I have a batch file containing this line :-   
   > CScript //nologo THING.JS   
   >   
   > That *.JS file finishes with :-   
   > WScript.echo(S)   
   >   
   > so that I can read the answer S in a small window.   
   >   
   > How, most straightforwardly, can I get the value of S (an alphanumeric   
   string of 10 characters) back to the batch file, for example as a local   
   environment variable accessible as %FRED% ??   
   >   
   > I have thought of using something like (untested)   
   > CScript.echo("set FRED=" + S),   
   > redirecting that output to a file ALEC.BAT, and executing that; but there   
   should be a better way.   
   >   
   > Speed is of no importance; it will typically be executed once a day at login   
   time. I do NOT want to rewrite THING.JS in pure Batch code.   
      
   You can redirect the output of CSCRIPT using `for /f` with the CSCRIPT   
   command line and parse its output. Or the output can be redirected into a   
   file first if a result file is needed.   
      
   e.g. the JS file part (test.js):   
      
   WScript.echo("Result from cscript");   
      
   The batch file part, with direct parsing, e.g.   
      
   @echo off   
   setlocal   
   set res=   
   for /f "delims=" %%A in ('cscript.exe //nologo test.js') do set "res=%%A"   
   echo result=%res%   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca