如何使用窗口标题启动Powershell? [英] How to start powershell with a window title?
问题描述
我有一个批处理文件,可让我根据输入内容转到特定的文件夹。
I have a batch file that allows me to go to particular folder based on my input.
d:
cd d:\test\bits
@ECHO off
cls
:start
ECHO.
ECHO 1. Perl
ECHO 2. Python
set choice=
set /p choice=type in number to go to appropriate code folder:
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto pl
if '%choice%'=='2' goto py
ECHO "%choice%" is not valid, try again
ECHO.
goto start
:pl
cd code\pl
goto end
:py
cd code\py
goto end
:end
start "bits"
在执行结束时,命令提示符标题为 bits的窗口将打开,并位于与输入选择相对应的指定目录中。一切都很好。但是我想用Powershell做同样的事情。
At the end of execution, a command prompt window with the title "bits" opens up and is in the specified directory corresponding to the input choice. This is all good. But I want to have the same thing done with Powershell.
如果不是代替开始位
,我放在 start powershell
中,在最后一行,我可以打开Powershell控制台。通过这样做,我有两个问题。
If, instead of start "bits"
, I put, start powershell
, in the last line, I can get Powershell console to open. By doing this, I have two issues.
- Powershell控制台仍位于
d:\test\bits
文件夹中, - 我无法获得标题为
bits
的标题
- Powershell console is still in
d:\test\bits
folder and not in the one I intended it to go. - I cannot get the title to be
bits
如何使用Powershell获得所需的功能?
How do I get the functionality I want with Powershell?
推荐答案
根据我的预期以及我能够使用您的脚本复制的内容,当前目录设置为预期的目录( d:\test\bits\code\pl
如果输入1)
From what I expected and what I was able to reproduce with your script, the current directory is set to the intended one (d:\test\bits\code\pl
if I enter 1)
对于标题部分,您可以执行以下操作:
For the title part, you can do the following:
start powershell -NoExit -command "$Host.UI.RawUI.WindowTitle = 'bits'"
这篇关于如何使用窗口标题启动Powershell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!