Take the 2-minute tour ×

I want to have a batch file which run a executable file(Test.exe). when test.exe is called it would open a command prompt environment.On this stage i want that some defined command(s) automatically be written on that prompt environment and then it hit enter automatically so that my command(s) run

share|improve this question
add comment

4 Answers

cmd /C string Carries out the command specified by string and then terminates the command prompt
cmd /K string Carries out the command specified by string but leaves the command prompt

The standard way to run multiple command at once is to separate each command with &&; for example, echo hello && pause will write "hello" to the command prompt, then wait for you to press a key. You can combine this with the /C or /K usage described above to run several commands. In order to use the visual studio command prompt, you may want to have the first command be to change the directory to whatever the VS Command Prompt directory is, using the cd command.

Other options include setting the path, turning echo on or off, etc. Run cmd /? from the command prompt to get detailed info on cmd.exe's command line arguments.

So, your batch file would probably look something like this:

start test.exe
start cmd.exe /C cd "%programfiles%\Microsoft Visual Studio x.x\VC" && title Visual Studio Command Prompt && command1 && command2 && command3
share|improve this answer
no, I just tried this,by this work the batch file just call both VC prompt & MODELER simultaneously but it s not the thing I expect; I want it calls vcvarsall.bat ,then when it is called the command "MODELER" entered through it automatically –  user44509 Aug 17 '10 at 18:36
I'm sorry, I don't completely follow what you said there. Could you clarify? Do you want to pipe "MODELER" to vcvarsall.bat? To do that, you would do echo MODELER | vcvarsall.bat, that sends the text "MODELER" to the first input that vcvarsall.bat gives you. –  nhinkle Aug 17 '10 at 20:39
add comment

For the sake of curiosity, why do you want to the commands to appear and run?

Nevertheless, the test.exe should be created using a programming language which supports opening applications and sending key strokes to it. Is there any programming language you are familiar with? That is if you want the test.exe to open the command prompt and do the job.

This is the .NET way of doing it

The more easy way is to call upon another batch file or the same batch file can be used. The batch file would have ECHO ON (by default ECHO is ON) so all the commands that you write on the batch file would be shown to the user, unless you do a ECHO OFF. But using method, i do not see why a test.exe would be required unless you want the test.exe to do something else other than opening a batch file and showing commands.

share|improve this answer
I think he already has test.exe, and he wants to create a batch file that inputs commands to it. –  Hello71 Aug 17 '10 at 15:40
okay,lets clear it more. my test.exe is Visual Studio 2008 command Prompt.I m calling different Modelers through that.So to save my time,I need that batch file that open "Visual Studio 2008 command Prompt" then automatically run those Modelers –  user44509 Aug 17 '10 at 15:42
add comment

So test.exe is sort of like a command prompt window (but specialized), and you want to make a script that executes commands in the Test application. Something like this should work:

First, create a file called, say myscript.cmd. Then, open Notepad and type this in:

test.exe < myscript.cmd
share|improve this answer
yes,I added some explanations below. –  user44509 Aug 17 '10 at 15:46
I did as above; the first part executed( prompt window appeared) but the second section myscript.cmd which contains command to call Modeler didn't either entered automatically or ran. –  user44509 Aug 17 '10 at 16:02
add comment

Have you tried PowerShell? Microsoft seems to be seeing the light around using a command-line and PowerShell seems to be their direction for the near future.

share|improve this answer
add comment

Your Answer


