简体   繁体   English

更改窗口命令提示符字符串

[英]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: 如您所见,这发生了变化:

  • prompt window title 提示窗口标题
  • prompt color 提示色
  • prompt string 提示字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何显示窗口和命令行提示符? - How to show Window and command-line prompt? 如何通过命令提示符启动exe并从命令提示符窗口获取文本 - How to launch an exe by command prompt and get text from command prompt window 摆脱win32中的命令提示符窗口 - Getting rid of the command prompt window in win32 如何防止COM Server EXE打开命令提示符窗口 - How to prevent COM Server EXE to open Command Prompt window 将命令提示符输出重定向到Visual Studio 2012中的输出窗口 - Redirect command prompt output to output window in Visual studio 2012 如何在C ++中从调用系统隐藏Matlab命令窗口和命令提示符 - How to hide Matlab Command Window and command prompt from calling system in C++ 如何从命令提示符将字符串传递给 omnetpp 模拟 - How to pass a string to omnetpp simulation from the command prompt 如何从命令提示符窗口构建和编译Visual Studio C ++代码 - How to build and compile visual studio c++ code from command prompt window 如何使命令提示符窗口在左上角打开? - How can I make the command prompt window open in the top left corner? 我应该怎么做才能使用新的命令提示符窗口来获得新的进程? - what should I do to get the new process using a new command prompt window?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM