0

I need to write a batch file script that can execute a text command in another CMD window that is already running. The secondary CMD window must not close afterwards, and it can be referenced by a window Title. There are a few 'cmd.exe' processes running in the environment and it would be ideal to have some kind of method to execute the command to the specific window by its title.

How would I go about doing this?

1 Answer 1

1

Batch files don't have the ability to interact with different windows. For that, you'll need to use either PowerShell or something like AutoHotkey / AutoIt

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the links. This system is designed to be run automatically from a PHP script (hopefully using exec()). How would I acheive the same effect using the two given options (PowerShell / AutoIt)?
Start your "child" command windows using cmd /k "title Foo1" (change Foo1 as needed); next you'll need a helper script:find the window by titlefor PowerShell use FindWindow dll call (see the PowerShell script link), for AutoIt use WinGetHandle() from AutoIt window functions to find the window by title; next in your helper script send the keystrokes + enter for the command you want run in that window

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.