如何预先填充一些字符的命令提示符?
问题描述:
在批处理文件中,我想打开一个命令提示符(并保持打开状态),并用“git clone”文本预填充命令,所以我只需要复制一个项目的URL。如何预先填充一些字符的命令提示符?
这是我如何打开一个命令提示符并添加git的环境变量(没有管理员权限):
foo.bat:
@ECHO OFF
if NOT "%1"=="" goto PROGRAM
cmd /k foo.bat DONT_CLOSE_PROMPT
EXIT
:PROGRAM
SET PATH=%PATH%;D:\Programme\Git\bin
d:
cd "D:\username\Documents\Visual Studio 2013\Projects"
REM cls
REM bar.bat
这是如何将文本添加到命令提示符:
bar.bat
@if (@CodeSection == @Batch) @then
@echo off
rem Enter the prefill value in the keyboard buffer
CScript //nologo //E:JScript "%~F0" "git clone "
goto :EOF
@end
WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0));
但显然我不能只是复制bar.bat我REM bar.bat在foo.bat中的地方。
Microsoft JScript中的编译错误:条件编译为 已关闭。
D:\ username \ Documents \ Visual Studio 2013 \ Projects> 我该怎么做(我不想要2个文件)?
注意:echo不会削减它,因为我需要能够在按Enter键前插入git clone的URL。
答
你需要获得条件编译块内的批处理脚本:
bar.bat
@if (@CodeSection == @Batch) @then
@echo off
if NOT "%1"=="" goto PROGRAM
cmd /k bar.bat DONT_CLOSE_PROMPT
EXIT
:PROGRAM
set SendKeys=CScript //nologo //E:JScript "%~F0"
SET PATH=%PATH%;D:\Programme\Git\bin
d:
cd "D:\username\Documents\Visual Studio 2013\Projects"
REM cls
%SendKeys% "git clone "
goto :EOF
@end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
代码的一些解释将是有益的人访问这个问题的第一次,只是说*“尝试”*没有帮助。 – Lankymart