Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 每行批次颜色_Batch File - Fatal编程技术网

Batch file 每行批次颜色

Batch file 每行批次颜色,batch-file,Batch File,在批处理中,每行可以有不同的颜色。 例如,如果您有一个批处理文件 “你好” “你好吗?” 请给我蓝色的“你好”和绿色的“你好”好吗 (我知道color命令,以及它对背景和文本的着色方式)无需任何外部程序即可完成。这是我几天前过来的东西。效果很好 @echo off SETLOCAL EnableDelayedExpansion for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in

在批处理中,每行可以有不同的颜色。 例如,如果您有一个批处理文件 “你好” “你好吗?”

请给我蓝色的“你好”和绿色的“你好”好吗


(我知道color命令,以及它对背景和文本的着色方式)

无需任何外部程序即可完成。这是我几天前过来的东西。效果很好

@echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  set "DEL=%%a"
)
echo say the name of the colors, don't read

call :ColorText 0a "blue"
call :ColorText 0C "green"
call :ColorText 0b "red"
echo(
call :ColorText 19 "yellow"
call :ColorText 2F "black"
call :ColorText 4e "white"

goto :eof

:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
@echo关闭
SETLOCAL EnableDelayedExpansion
对于/F“tokens=1,2 delims=#”%%a in(‘“prompt#$H#$E#&echo on&for%%b in(1)do rem“’)do(
设置“DEL=%%a”
)
回声说颜色的名字,不要读
调用:ColorText 0a“蓝色”
调用:彩色文本0C“绿色”
调用:彩色文本0b“红色”
回音(
调用:ColorText 19“黄色”
调用:ColorText 2F“黑色”
调用:ColorText 4e“白色”
后藤:eof
:彩色文本
回音
"%~2"
findstr/v/a:%1/R“^$”“%~2”个
删除“%~2”>nul 2>&1
后藤:eof
归功于
下面的批处理文件创建COLORMSG.COM文件(根据需要重命名),该文件以以下方式显示带有颜色的消息:
COLORMSG color“message”

在消息之后,光标不会移动到新行,因此可能会在同一行中显示多条消息。要以更简单的方式显示颜色,可以使用以下定义:

set Black=0&       set Gray=8
set Blue=1&        set LightBlue=9
set Green=2&       set LightGreen=A
set Aqua=3&        set LightAqua=B
set Red=4&         set LightRed=C
set Purple=5&      set LightPurple=D
set Yellow=6&      set LightYellow=E
set White=7&       set BrightWhite=F
例如:

colormsg %Yellow% "Message in yellow  "
colormsg %Blue%%BrightWhite% "Bright white text over blue background"
@echo off
setlocal EnableDelayedExpansion
set i=0
for %%c in (Blk Blu Grn Aqu Red Pur Yel Whi) do (
    set color[!i!]=%%c
    set /A i+=1
)
for /L %%j in (0,1,7) do (
    set color[!i!]=L!color[%%j]:~0,-1!
    set /A i+=1
)    
cls
echo/
echo           BACKGROUND / FOREGROUND COMBINATIONS OF AVAILABLE SCREEN COLORS
echo/
echo/
colormsg 7 "ForeGrnd:"
for /L %%i in (0,1,15) do colormsg 7 " !color[%%i]!"
echo/
echo BackGrnd
set i=0
for /L %%b in (0,1,9) do call :ShowLine %%b
for %%b in (A B C D E F) do call :ShowLine %%b
echo/
goto :eof

:ShowLine
colormsg 7 "   !color[%i%]!   "
set /A i+=1
for /L %%f in (0,1,9) do colormsg %1%%f " %1%%f "
for %%f in (A B C D E F) do colormsg %1%%f " %1%%f "
echo/
textpos 0 0
colormsg %Red% "Red message at top left corner of the screen"
textpos 10 40
colormsg %Blue%%LightYellow% "This message start in line 10 column 40"
这是一个更大的例子:

colormsg %Yellow% "Message in yellow  "
colormsg %Blue%%BrightWhite% "Bright white text over blue background"
@echo off
setlocal EnableDelayedExpansion
set i=0
for %%c in (Blk Blu Grn Aqu Red Pur Yel Whi) do (
    set color[!i!]=%%c
    set /A i+=1
)
for /L %%j in (0,1,7) do (
    set color[!i!]=L!color[%%j]:~0,-1!
    set /A i+=1
)    
cls
echo/
echo           BACKGROUND / FOREGROUND COMBINATIONS OF AVAILABLE SCREEN COLORS
echo/
echo/
colormsg 7 "ForeGrnd:"
for /L %%i in (0,1,15) do colormsg 7 " !color[%%i]!"
echo/
echo BackGrnd
set i=0
for /L %%b in (0,1,9) do call :ShowLine %%b
for %%b in (A B C D E F) do call :ShowLine %%b
echo/
goto :eof

:ShowLine
colormsg 7 "   !color[%i%]!   "
set /A i+=1
for /L %%f in (0,1,9) do colormsg %1%%f " %1%%f "
for %%f in (A B C D E F) do colormsg %1%%f " %1%%f "
echo/
textpos 0 0
colormsg %Red% "Red message at top left corner of the screen"
textpos 10 40
colormsg %Blue%%LightYellow% "This message start in line 10 column 40"
嘿,Gareth,这是给你的奖励!下面的批处理文件创建TEXTPOS.COM文件(根据你的意愿重命名),可以将光标移动到任意行和列:
TEXTPOS line col

@echo off
(
echo e100
echo 0F B6 0E 80 00 E3 2D BF 81 00 B0 20 FC F3 AE 74
echo e110
echo 23 E3 21 8D 75 FF E8 45 00 3C 20 75 3B 86 F2 E8
echo e120
echo 3C 00 86 F2 3C 20 74 04 3C 0D 75 2C 32 FF B4 02
echo e130
echo CD 10 EB 24 32 FF B4 03 CD 10 8A C6 8A CA E8 38
echo e140
echo 00 B2 20 B4 02 CD 21 8A C1 E8 2D 00 B2 0D B4 02
echo e150
echo CD 21 B2 0A B4 02 CD 21 32 C0 B4 4C CD 21 32 E4
echo e160
echo AC 3C 20 74 FB 3C 30 72 0D 3C 39 77 09 2C 30 D5
echo e170
echo 0A 8A E0 AC EB EF 8A F4 C3 D4 0A 05 30 30 8B D0
echo e180
echo 80 FC 30 74 08 86 D6 B4 02 CD 21 8A D6 B4 02 CD
echo e190
echo 21 C3
echo rcx
echo 92
echo w
echo q
) | debug textpos.com > nul
例如:

colormsg %Yellow% "Message in yellow  "
colormsg %Blue%%BrightWhite% "Bright white text over blue background"
@echo off
setlocal EnableDelayedExpansion
set i=0
for %%c in (Blk Blu Grn Aqu Red Pur Yel Whi) do (
    set color[!i!]=%%c
    set /A i+=1
)
for /L %%j in (0,1,7) do (
    set color[!i!]=L!color[%%j]:~0,-1!
    set /A i+=1
)    
cls
echo/
echo           BACKGROUND / FOREGROUND COMBINATIONS OF AVAILABLE SCREEN COLORS
echo/
echo/
colormsg 7 "ForeGrnd:"
for /L %%i in (0,1,15) do colormsg 7 " !color[%%i]!"
echo/
echo BackGrnd
set i=0
for /L %%b in (0,1,9) do call :ShowLine %%b
for %%b in (A B C D E F) do call :ShowLine %%b
echo/
goto :eof

:ShowLine
colormsg 7 "   !color[%i%]!   "
set /A i+=1
for /L %%f in (0,1,9) do colormsg %1%%f " %1%%f "
for %%f in (A B C D E F) do colormsg %1%%f " %1%%f "
echo/
textpos 0 0
colormsg %Red% "Red message at top left corner of the screen"
textpos 10 40
colormsg %Blue%%LightYellow% "This message start in line 10 column 40"
编辑

我稍微修改了TEXTPOS程序,以便在没有参数的情况下执行时显示当前光标位置;此功能允许以以下方式将光标位置存储在变量中:
TEXTPOS>pipe.txt&set/p pos=
(因为
TEXTPOS | set/p pos=
有错误且不起作用)

如果显示的颜色消息的背景色和前景色的值相同,则文本将在屏幕上不可见;此功能允许输入密码。例如,这是
getpassword.bat
文件:

@echo off
set password=
for /L %%i in (1,1,%1) do set password=!password!x
colormsg 7 "Enter password: "
textpos > pipe.txt & set /P passpos=< pipe.txt
colormsg 77 "%password%"
textpos %passpos%
set password=
for /L %%i in (1,1,%1) do (
    getakey
    set password=!password!!errorlevel!
    colormsg 7F "*"
)
我在前面的一个问题中提供了GETAKEY.COM程序,但这里再次说明:

@echo off
(
echo e100
echo B4 08 CD 21 B4 4C CD 21
echo rcx
echo 8
echo w
echo q
) | debug getakey.com > nul
你可以试试这个 只需要一点命令:

@echo off
chcp 437>nul&&graftabl 936>nul
ren %WinDir%\System32\config.nt config.nt.bak 2>nul
<"%~f0" more +6 >%WinDir%\System32\config.nt
command /cecho [1;31mHel[32mlo [33mHow[35mare[36myou[m
pause>nul&exit
DOSONLY
dos=high, umb
device=%SystemRoot%\system32\himem.sys
DEVICE==%SystemRoot%\System32\ANSI.SYS /x
files=40
@echo关闭
chcp 437>nul和graftabl 936>nul
ren%WinDir%\System32\config.nt config.nt.bak 2>nul
%WinDir%\System32\config.nt
指挥部/塞乔[1;31英里/小时[32英里/小时[33英里/小时[36英里/小时]
暂停>取消并退出
多斯诺
dos=高,umb
设备=%SystemRoot%\system32\himem.sys
设备==%SystemRoot%\System32\ANSI.SYS/x
文件=40
是的,可以使用:


将此代码另存为
.bat
(它是自编译的.net混合版):

@if(@X)==(@Y)@end/*JScript注释
@回音
setlocal
对于/f“tokens=*delims=“%%v in('dir/b/s/a:-d/o:-n”%SystemRoot%\Microsoft.NET\Framework\*jsc.exe“)do(
设置“jsc=%%v”
)
如果不存在“%~n0.exe”(
%jsc%/nologo/out:“%~n0.exe”“%~dpsfnx0”
)
%~n0.exe%*
结束本地和退出/b%错误级别%
*/
进口制度;
变量参数:String[]=Environment.GetCommandLineArgs();
var newLine=false;
var输出=”;
var foregroundColor=Console.foregroundColor;
var backgroundColor=Console.backgroundColor;
var=false;
var currentBackground=Console.BackgroundColor;
var currentForeground=Console.ForegroundColor;
//http://stackoverflow.com/a/24294348/388389
var jsEscapes={
“n”:“\n”,
“r”:“\r”,
“t”:“\t”,
“f”:“\f”,
“v”:“\v”,
“b”:“\b”
};
函数decodeJsEscape(u0,hex0,hex1,八进制,其他){
var hex=hex0 | | hex1;
if(hex){return String.fromCharCode(parseInt(hex,16));}
if(八进制){返回字符串.fromCharCode(parseInt(八进制,8));}
返回jsEscapes[其他]| |其他;
}
函数decodeJsString(个){
退换货(
//将转义序列与组1中的UTF-16、组2中的单字节十六进制匹配,
//第3组为八进制,第4组为任意其他单字符转义。
/\\(?:u([0-9A-Fa-f]{4})| x([0-9A-Fa-f]{2})|([0-3][0-7]{0,2}|[4-7][0-7])|()/g,
解码(逃逸);
}
函数printHelp(){
打印(参数[0]+“-s字符串[-f前台][-b后台][-n][-e]”;
打印(“”);
打印(“要打印的字符串”);
打印(“前景色-a”);
打印(“0到15之间的数字”);
打印(“背景色-a”);
打印(“0到15之间的数字”);
print(“-n表示是否需要新行”);
打印(“写在合同末尾”);
打印(“字符串(默认为-否)”;
打印(“-e表示特殊字符”);
打印(“像\\n\\b\\r等序列”);
打印(“”);
印刷品(“颜色:”);
对于(var C=0;C<16;C++){
Console.BackgroundColor=c;
控制台。写(“”);
Console.BackgroundColor=currentBackground;
控制台。写入(“-”+c);
控制台。写线(“”);
}
Console.BackgroundColor=currentBackground;
}
函数错误检查器(e:错误){
如果(e.message==“输入字符串的格式不正确。”){
打印(“颜色参数应为介于0和15之间的数字”);
环境。出口(1);
}else if(e.message==“索引超出了数组的边界。”){
打印(“无效参数”);
环境。出口(2);
}否则{
打印(“错误消息:”+e.Message);
打印(“错误代码:”+(e.number&0xFFFF));
打印(“错误名称:”+e.Name);
环境。出口(666);
}
}
函数编号检查器(i:Int32){
如果(i>15 | | i<0){
打印(“颜色参数应为介于0和15之间的数字”);
环境。出口(1);
}
}
if(arguments.length==1 | | | arguments[1]。toLowerCase()==“-help”| | arguments[1]。toLowerCase()==“-help”){
打印帮助();
环境。退出(0);
}
对于(变量arg=1;arg<
@echo off
if "%~3" == "" goto usage
powershell -command write-host -foreground "%~1" -background "%~2" -nonewline "%~3"
exit /b
:usage
echo.
echo Usage: call colormsg foreground background "message"
echo.
echo Examples:
echo call colormsg white blue "example1"
echo call colormsg 4 2 "example2"
@echo off
for /f %%a in ('"prompt $H & for %%a in (-) do rem"') do set "BS=%%a"
call colormsg blue 0 "Hello"
<nul set /p "=.%BS% "
call colormsg green 0 "How are you?"
echo.
pause
@echo off
(
echo e100
echo 0F B6 0E 80 00 E3 4F BF 81 00 B0 20 FC F3 AE 74
echo e110
echo 45 E3 43 8A 45 FF E8 43 00 80 3D 20 74 0E C0 E0
echo e120
echo 04 8A E0 8A 05 E8 34 00 0A C4 47 49 E3 28 32 E4
echo e130
echo 50 B0 22 F2 AE 75 1F E3 1D 8B F7 8B D1 F2 AE 75
echo e140
echo 01 41 2B D1 74 10 8B CA 5B B0 20 B4 09 CD 10 AC
echo e150
echo B4 0E CD 10 E2 F9 32 C0 B4 4C CD 21 3C 61 72 02
echo e160
echo 2C 20 3C 41 72 02 2C 07 2C 30 C3
echo rcx
echo 6b
echo w
echo q
) | debug colormsg.com > nul
ren colormsg.com colormsg.exe
color /?
@echo off

REM one color in line
echo.
colormsg a "green color"

REM break line
echo.

REM two colors in line
colormsg b "color blue"
colormsg c "color red"

REM break line
echo.

REM two colors with spacing horizontally (no use tab)
colormsg d "purple color"
colormsg e "             yellow color"
echo.
echo.
pause
@echo off
rem Script written by BrendanSilva [bl8086]
rem You need DEBUG.EXE executable in your system.
setlocal enabledelayedexpansion
set /a _er=0
set /a _n=0
set _ln=%~4
goto init
:howuse ------------------------------------------------------------------------
    echo.
    echo ECOL.BAT - v2.0
    echo Print colored text as batch script without temporary files.
    echo Written by bl8086
    echo.
    echo Syntax:
    echo ECOL.BAT [COLOR] [X] [Y] "Insert your text here"
    echo COLOR value must be a hexadecimal number like "color /?" information
    echo.
    echo Example:
    echo ECOL.BAT F0 20 30 "640K ought to be enough for anybody."
    echo.
    goto :eof
:error ------------------------------------------------------------------------
    set /a "_er=_er | (%~1)"
    goto :eof
:gcnvhx ------------------------------------------------------------------------
    set _cvhx=
    set /a _cvint=%~1
:cnvhx
    set /a "_gch = _cvint & 0xF"
    set _cvhx=!nsys:~%_gch%,1!%_cvhx%
    set /a "_cvint = _cvint >> 4"
    if !_cvint! neq 0 goto cnvhx
    goto :eof
:init --------------------------------------------------------------------------
    if "%~4"=="" call :error 0xff
    (
        set /a _cl=0x%1
        call :error !errorlevel!
        set _cl=%1
        call :error "0x!_cl! ^>^> 8"
        set /a _px=%2
        call :error !errorlevel!
        set /a _py=%3
        call :error !errorlevel!
    ) 2>nul 1>&2
    if !_er! neq 0 (
        echo.
        echo ERROR: value exception "!_er!" occurred. Check memory out.
        echo.
        goto howuse
    )
    set nsys=0123456789ABCDEF
    set /a cnb=0
    set /a cnl=0
    set _cvhx=0
    set _cvint=0
    set _cvmhx=0
:parse -------------------------------------------------------------------------
    set _ch=!_ln:~%_n%,1!
    if "%_ch%"=="" goto perform
    set /a "cnb += 1"
    if %cnb% gtr 7 (
        set /a cnb=0
        set /a "cnl += 1"
    )
    set bln%cnl%=!bln%cnl%! "!_ch!" %_cl%
    set /a "_n += 1"
    goto parse
:perform -----------------------------------------------------------------------
    set /a "in = ((_py * 0xA0) + (_px << 1)) & 0xFFFF"
    call :gcnvhx %in%
    set ntr=!_cvhx!
    set /a jmp=0xe
    set bl8086str=echo.h 0 0
    @for /l %%x in (0,1,%cnl%) do (
        set bl8086str=!bl8086str!^&echo.eb800:!ntr! !bln%%x!
        set /a "in=!jmp! + 0x!ntr!"
        call :gcnvhx !in!
        set ntr=!_cvhx!
        set /a jmp=0x10
    )
    (
    echo %bl8086str%
    echo.q
    ) |debug >nul 2>&1
::
:: Launch a PowerShell child process in the background linked to the console and 
:: earing through named pipe PowerShellCon_%PID%
::
:: Parameters :
::   [ PID ] : Console Process ID used as an identifier for the named pipe, launcher PID by default.
::   [ timeout ] : Subprocess max life in seconds, 300 by default. If -1, the subprocess
::                  will not terminate while the process %PID% is still alive.
:: Return :
::   0 if the child PowerShell has been successfully launched and the named pipe is available.
::   1 if it fails.
::   2 if we can't get a PID.
::   3 if PowerShell is not present or doesn't work.
::
:LaunchPowerShellSubProcess
  SET LOCALV_PID=
  SET LOCALV_TIMEOUT=300
  IF NOT "%~1" == "" SET LOCALV_PID=%~1
  IF NOT "%~2" == "" SET LOCALV_TIMEOUT=%~2
  powershell -command "$_" 2>&1 >NUL
  IF NOT "!ERRORLEVEL!" == "0" EXIT /B 3
  IF "!LOCALV_PID!" == "" (
    FOR /F %%P IN ('powershell -command "$parentId=(Get-WmiObject Win32_Process -Filter ProcessId=$PID).ParentProcessId; write-host (Get-WmiObject Win32_Process -Filter ProcessId=$parentId).ParentProcessId;"') DO (
      SET LOCALV_PID=%%P
    )
  )
  IF "!LOCALV_PID!" == "" EXIT /B 2
  START /B powershell -command "$cmdPID=$PID; Start-Job -ArgumentList $cmdPID -ScriptBlock { $ProcessActive = $true; $timeout=!LOCALV_TIMEOUT!; while((!LOCALV_TIMEOUT! -eq -1 -or $timeout -gt 0) -and $ProcessActive) { Start-Sleep -s 1; $timeout-=1; $ProcessActive = Get-Process -id !LOCALV_PID! -ErrorAction SilentlyContinue; } if ($timeout -eq 0 -or ^! $ProcessActive) { Stop-Process -Id $args; } } | Out-Null ; $npipeServer = new-object System.IO.Pipes.NamedPipeServerStream('PowerShellCon_!LOCALV_PID!', [System.IO.Pipes.PipeDirection]::In); Try { $npipeServer.WaitForConnection(); $pipeReader = new-object System.IO.StreamReader($npipeServer); while(($msg = $pipeReader.ReadLine()) -notmatch 'QUIT') { $disp='write-host '+$msg+';'; invoke-expression($disp); $npipeServer.Disconnect(); $npipeServer.WaitForConnection(); }; } Finally { $npipeServer.Dispose(); }" 2>NUL
  SET /A LOCALV_TRY=20 >NUL
  :LaunchPowerShellSubProcess_WaitForPipe
  powershell -nop -c "& {sleep -m 50}"
  SET /A LOCALV_TRY=!LOCALV_TRY! - 1 >NUL
  IF NOT "!LOCALV_TRY!" == "0" cmd /C "ECHO -NoNewLine|MORE 1>\\.\pipe\PowerShellCon_!LOCALV_PID!" 2>NUL || GOTO:LaunchPowerShellSubProcess_WaitForPipe
  IF "!LOCALV_TRY!" == "0" EXIT /B 1
  EXIT /B 0
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
IF ERRORLEVEL 1 (
  ECHO Extension inapplicable
  EXIT /B 1
)
::
SETLOCAL ENABLEDELAYEDEXPANSION
IF ERRORLEVEL 1 (
  ECHO Expansion inapplicable
  EXIT /B 1
)
CALL:LaunchPowerShellSubProcess
IF NOT ERRORLEVEL 0 EXIT /B 1
CALL:Color Cyan "I write this in Cyan"
CALL:Blue "I write this in Blue"
CALL:Green "And this in green"
CALL:Red -nonewline "And mix Red"
CALL:Yellow "with Yellow"
CALL:Green "And not need to trouble with ()<>&|;,%""^ and so on..."
EXIT /B 0
:Color
ECHO -foregroundcolor %*>\\.\pipe\PowerShellCon_!LOCALV_PID!
ECHO[|SET /P=>NUL
GOTO:EOF
:Blue
ECHO -foregroundcolor Blue %*>\\.\pipe\PowerShellCon_!LOCALV_PID!
ECHO[|SET /P=>NUL
GOTO:EOF
:Green
ECHO -foregroundcolor Green %*>\\.\pipe\PowerShellCon_!LOCALV_PID!
ECHO[|SET /P=>NUL
GOTO:EOF
:Red
ECHO -foregroundcolor Red %*>\\.\pipe\PowerShellCon_!LOCALV_PID!
ECHO[|SET /P=>NUL
GOTO:EOF
:Yellow
ECHO -foregroundcolor Yellow %*>\\.\pipe\PowerShellCon_!LOCALV_PID!
ECHO[|SET /P=>NUL
GOTO:EOF
::
:: Launch a PowerShell child process in the background linked to the console and 
:: earing through named pipe PowerShellCon_%PID%
::
:: Parameters :
::   [ PID ] : Console Process ID used as an identifier for the named pipe, launcher PID by default.
::   [ timeout ] : Subprocess max life in seconds, 300 by default. If -1, the subprocess
::                  will not terminate while the process %PID% is still alive.
:: Return :
::   0 if the child PowerShell has been successfully launched and the named pipe is available.
::   1 if it fails.
::   2 if we can't get a PID.
::   3 if PowerShell is not present or doesn't work.
::
:LaunchPowerShellSubProcess
  SET LOCALV_PID=
  SET LOCALV_TIMEOUT=300
  IF NOT "%~1" == "" SET LOCALV_PID=%~1
  IF NOT "%~2" == "" SET LOCALV_TIMEOUT=%~2
  powershell -command "$_" 2>&1 >NUL
  IF NOT "!ERRORLEVEL!" == "0" EXIT /B 3
  IF "!LOCALV_PID!" == "" (
    FOR /F %%P IN ('powershell -command "$parentId=(Get-WmiObject Win32_Process -Filter ProcessId=$PID).ParentProcessId; write-host (Get-WmiObject Win32_Process -Filter ProcessId=$parentId).ParentProcessId;"') DO (
      SET LOCALV_PID=%%P
    )
  )
  IF "!LOCALV_PID!" == "" EXIT /B 2
  START /B powershell -command "$cmdPID=$PID; Start-Job -ArgumentList $cmdPID -ScriptBlock { $ProcessActive = $true; $timeout=!LOCALV_TIMEOUT!; while((!LOCALV_TIMEOUT! -eq -1 -or $timeout -gt 0) -and $ProcessActive) { Start-Sleep -s 1; $timeout-=1; $ProcessActive = Get-Process -id !LOCALV_PID! -ErrorAction SilentlyContinue; } if ($timeout -eq 0 -or ^! $ProcessActive) { Stop-Process -Id $args; } } | Out-Null ; $npipeServer = new-object System.IO.Pipes.NamedPipeServerStream('PowerShellCon_!LOCALV_PID!', [System.IO.Pipes.PipeDirection]::In); Try { $npipeServer.WaitForConnection(); $pipeReader = new-object System.IO.StreamReader($npipeServer); while(($msg = $pipeReader.ReadLine()) -notmatch 'QUIT') { $disp='write-host '+$msg+';'; invoke-expression($disp); $npipeServer.Disconnect(); $npipeServer.WaitForConnection(); }; } Finally { $npipeServer.Dispose(); }" 2>NUL
  SET /A LOCALV_TRY=20 >NUL
  :LaunchPowerShellSubProcess_WaitForPipe
  powershell -nop -c "& {sleep -m 50}"
  SET /A LOCALV_TRY=!LOCALV_TRY! - 1 >NUL
  IF NOT "!LOCALV_TRY!" == "0" cmd /C "ECHO -NoNewLine|MORE 1>\\.\pipe\PowerShellCon_!LOCALV_PID!" 2>NUL || GOTO:LaunchPowerShellSubProcess_WaitForPipe
  IF "!LOCALV_TRY!" == "0" EXIT /B 1
  EXIT /B 0