用于更改cmd目录和预填充命令的批处理文件 [英] Batch file for changing cmd directory and pre-filling a command

查看:80
本文介绍了用于更改cmd目录和预填充命令的批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力寻找细节,没有运气.

I've searched long and hard to get details on this, with no luck.

我要做的只是:

  1. 打开CMD
  2. 更改我的工作目录
  3. 输入文本字符串命令,然后在此处暂停,以便我可以手动输入命令的最后一部分并按Enter

示例:

@ECHO OFF
start cmd.exe /K "cd C:\ProgramData\Microsoft\Windows\Start Menu"

我的前半部分可以正常工作,它可以打开cmd并更改目录-但是此时如何将文本字符串填充到窗口中?

I have the first half of it working fine, it opens cmd and changes the directory - but how do I fill in the text string into the window at this point?

推荐答案

好的,您要:

  • 打开CMD
  • 更改我的工作目录
  • 输入文本字符串命令,然后在此处暂停,以便我可以手动输入命令的最后一部分并按Enter

然后呢?之后,有两个 cmd.exe会话处于活动状态,因此以下输入将有问题.下面的批处理文件允许您执行所需的操作,但是存在下一步要执行的问题.试试看并提供反馈,以便我们修复细节.

And then? After that there are two cmd.exe sessions active, so it will be problems with the following input. The Batch file below allows you do to what you want, but have the problem of what to do next. Try it and give feedback, so we can fix the details.

@if (@CodeSection == @Batch) @then

@echo off

rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"

rem Start cmd.exe program 
start "" cmd

rem Send whatever you want to previous cmd.exe
%SendKeys% "echo Hello world!{ENTER}"
%SendKeys% "cd C:\ProgramData\Microsoft\Windows\Start Menu{ENTER}"
%SendKeys% "echo You continue at this point: "

set /P "="
ECHO TERMINATE ORIGINAL BATCH
goto :EOF

@end

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));

这篇关于用于更改cmd目录和预填充命令的批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆