Code: Select all
@if (@CodeSection == @Batch) @then
@echo off
if "%1" equ "Restart" goto Restart
cd . >pipe.txt
"%~F0" Restart 3>&1 1>&2 4<pipe.txt | CScript //nologo //E:JScript "%~F0" >>pipe.txt
goto :EOF
:Restart
echo This appear on the screen
set /P "stdinput=Keyboard input: "
echo READ via keyboard: "%stdinput%"
echo ACTION: This is a command sent to the JScript section >&3
echo Next line was sent to Stderr
verify bad
call :sendReceive "ECHO: This line must be taken in the Batch file"
echo BATCH: Received "%ln%"
echo Last line on screen
REM del pipe.txt
goto :EOF
:sendReceive
echo BATCH: Sending %1
>&3 echo %~1
set "ln="
:getInput
set /p "ln=" <&4
if not defined ln goto :getInput
exit /b
@end
// JScript section
var line, command;
while ( !WScript.StdIn.AtEndOfStream ) {
line = WScript.Stdin.ReadLine();
WScript.Stderr.WriteLine('JScript received: "'+line+'"');
command = line.split(" ")[0];
if ( command == "ECHO:" ) {
WScript.Stderr.WriteLine('JScript sending: "OK - '+line+'"');
WScript.Stdout.WriteLine("OK - "+line);
} else {
// Any other action, no screen output
}
}
Output:
Code: Select all
This appear on the screen
Keyboard input: keys+keys
READ via keyboard: "keys+keys"
JScript received: "ACTION: This is a command sent to the JScript section "
Next line was sent to Stderr
Parámetro
incorrecto en el comando.
BATCH: Sending "ECHO: This line must be taken in the Batch file"
JScript received: "ECHO: This line must be taken in the Batch file"
JScript sending: "OK - ECHO: This line must be taken in the Batch file"
BATCH: Received "OK - ECHO: This line must be taken in the Batch file"
Last line on screen
Antonio