Page 1 of 1

How to issue command but not have it execute

Posted: 28 Mar 2023 19:56
by Maverick
I need to open up the command shell within a very specific directory, let's say "C:\My Project". I did a little bit of searching on the internet and found a very simple batch file.

Code: Select all

cd /d %~dp0
Start cmd.exe
This works fine but I need to have the letters "fc.exe" typed at the command prompt as soon as the command shell opens. I tried the following:
Start cmd.exe /k "fc.exe "

The problem with this is that it executes the fc.exe command. That's no good. The program needs arguments or parameters to run so running fc.exe by itself produces nothing.

Any solutions?

Re: How to issue command but not have it execute

Posted: 30 Mar 2023 12:49
by Aacini
Mmm... Think a minute about this request: "Issue a command but not have it execute" Makes this any sense to you? (neither for me).

This phrase makes more sense: "have the letters "fc.exe" typed at the command prompt"

At this SO answer there is the solution to a request similar to yours: I would like to know how to automate an input of data.

This is the simplified solution:

Code: Select all

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


@echo off

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

rem Send the keys...
%SendKeys% "fc.exe "

rem ... and run cmd.exe
cmd.exe

goto :EOF


@end


// JScript section

WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0));
It works! (just tested)

Antonio