将CMD标题设置为正斜杠和问号(批处理)

时间:2017-03-02 03:09:10

标签: batch-file

我想知道是否可以将CMD的窗口标题更改为/?

我已尝试使用^/?^/^?"/?",但似乎没有一个可以使用。

有人有任何建议吗?

由于

2 个答案:

答案 0 :(得分:5)

添加一些不可见的字符是可能的 这个想法取自@npocmaka SO: How can I set set a title that start with coma,semicolon or equal sign?
带有起始逗号的标题的问题也可以用LF字符解决,但在你的情况下,LF对字符串中的任何地方都没有帮助。

@echo off

(set LF=^
%=empty=%
)

::Create a FS variable
call :hexprint "0x1C" FS

title /%FS%?
exit /b

:hexPrint  string  [rtnVar]
  for /f eol^=^%LF%%LF%^ delims^= %%A in (
    'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(%~1"'
  ) do if "%~2" neq "" (set %~2=%%A) else echo(%%A
exit /b

答案 1 :(得分:1)

@ECHO OFF
if "%~1"=="_SO42546112_" (
    shift
) else (
    start "/?" cmd /D /K ""%~f0" "_SO42546112_""
    exit
)

要使用CMD窗口标题启动 /?命令提示符,请在.bat脚本上方双击。

要使用.bat窗口标题运行/?脚本,请使用上述概念,例如如下:

@ECHO OFF
SETLOCAL EnableExtensions

rem self wrapper - start
if "%~1"=="_SO42546112_" (
    shift
) else (
    start "/?" cmd /D /C ""%~f0" "_SO42546112_" %*"
    exit /B
    rem  ↑↑  omit the `/B` switch to close calling `cmd` window
)
rem self wrapper - end

rem check whether the self wrapper works - start   
echo 1st "%~1"
echo 2nd "%~2"
echo 3rd "%~3"
echo all %*
pause
rem check whether the self wrapper works - end

rem original script continues here: