[英]Change window command prompt string
I want to change the command prompt string in a windows command prompt? 我想在Windows命令提示符中更改命令提示符字符串吗?
For example. 例如。
C:\\current\\path -> $CustomPrompt> C:\\ current \\ path-> $ CustomPrompt>
If possible, I would prefer the solution to make use of the winapi. 如果可能的话,我希望解决方案能够利用winapi。 I already looked at some of the console functions, but I cannot find any that I would assume wold manipulate the prompt string? 我已经看过一些控制台功能,但是找不到任何我会假设wold操作提示字符串的功能? Does anyone know how to do this? 有谁知道如何做到这一点?
Command Prompt String is definied as environmental variable PROMPT. 命令提示符字符串定义为环境变量PROMPT。 You can modify this variable using setenv()
function from cstdlib
: 您可以使用cstdlib
setenv()
函数修改此变量:
#include <stdlib.h>
//...
setenv("PROMPT", "$A$A", true);
This will, for example, set prompt string to '&&' (double ampersand). 例如,这会将提示字符串设置为“ &&”(双“&”号)。 For more interesting examples check this out. 欲了解更多有趣的例子检查这出。
EDIT: There is a way to achieve this without need to restart command interpreter. 编辑:有一种方法可以做到这一点,而不需要重新启动命令解释程序。 Create following batch file: 创建以下批处理文件:
@echo off
break off
title custom command prompt
color 0a
cls
:cmd
set /p cmd=command:
%cmd%
echo.
goto cmd
Lets name it "change_prompt.bat" Then, in your c++ code execute the batch file: 让我们将其命名为“ change_prompt.bat”。然后,在您的c ++代码中执行批处理文件:
system("change_prompt.bat");
As a result, prompt will look like this: 结果,提示将如下所示:
As you can see, this changes: 如您所见,这发生了变化:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.