Jump to content

Batch files confusion


Recommended Posts

I have a few questions about batch files I can't seem to google any clear answer to.

When starting unspecified programs from a .cmd batch file, does it make any difference if I use start command or not?

What's the difference between "start xyz.exe" and "cmd xyz.exe"? Both seem to be doing the same thing, but I do know there are some major differences there. I also see both being used at the same time, sometimes (like in the case of starting batch files from Windows 7's answer file for example).

Basically, starting a program can be done by just using the .exe's name, by using cmd command, by using start command, or by combination of the last two. I am completely lost. Help!

Edited by TheWalrus
Link to comment
Share on other sites


I was being as vague as your question because there is no answer for unspecified programs, only for specified ones. You didn't specify any therefore we cannot provide you a definitive answer.

As a general rule for running GUI applications from a batch file neither start or cmd have much purpose for you.

Link to comment
Share on other sites

lol. I was trying to be as general as possible, and I overshot

Basically I meant some random .exe, typically an installer of some sort, but I really wanted to avoid going into specifics.

Edited by TheWalrus
Link to comment
Share on other sites

So you are asking what in general the practical differences are in the results from the following 4 different statements when they are made inside a .cmd batch file, correct?

1) xyz.exe

2) cmd xyz.exe

3) start xyz.exe

4) cmd start xyz.exe

And I assume you are curious under which circumstances you should use each format?

Cheers and Regards

Link to comment
Share on other sites

There is no definitive answer here it is often dependant upon the specific .exe,

But generally, for installers from a batch file, there is no reason to prepend with cmd, even less reason to prepend with cmd and start and unless you have issues simply invoking the installer directly, no real reason to use start.

Link to comment
Share on other sites

I know one of the differences is whether the cmd window remains visible while the commend is executing or merely flashes briefly, and I'm sorry but I don't remember which format does what. And, of course, we haven't mentioned about when, or whether, it is helpful to include "/wait" along with "start", but I know there is some misunderstanding/disagreement about that.

Cheers and Regards

Edited by bphlpt
Link to comment
Share on other sites

What's the difference between "start xyz.exe" and "cmd xyz.exe"? Both seem to be doing the same thing, but I do know there are some major differences there.

cmd xyz.exe fails as it should so I am unsure why no one sees the issue.The syntax is invalid.

CMD expects a script to be passed to it unless you use /c or /k to invoke command line mode. Passing an executable to CMD as parameter without the previous switches is invalid to CMD so you should consider yourself lucky if it does work as it fails for me.

If you can run a command from a script without using Start, then why add it. Note that Start is an internal command so it has a little overhead to add to the process. I personally do not care if you use it as I consider that it will not hurt too much. The use of CMD /C in a command file is invoking a separate instance of the command interpreter which is indeed an overhead of being another process, more memory and more differcult debugging.

When to use Start?


notepad.exe
:: cmd notepad.exe REM stops here returning to a prompt so commented to run all script
cmd /c notepad.exe
start /wait "notepad.exe"

www.msfn.org
:: cmd www.msfn.org REM stops here returning to a prompt so commented to run all script
cmd /c www.msfn.org
start www.msfn.org

pause

The most direct commands would be notepad.exe and start www.msfn.org.

@bphlpt

Executions in a command script are processed one after the other in sequence. This means each command is executed and the next command does not start until the previous command completes. If it did not do that by default then you would have a race condition happening and many scripts may fail with handling the return value of the previous command. If you use Start, then the process will continue without waiting so you can do other commands without concern to the Started process previously executed. If you use Start /Wait then the behavior of moving to the next execution is the same as the default of waiting in a script.

To do a series of commands at an interactive command prompt like in the creation of a script is to first type the char ( , press the return key and then type each command line. When done adding commands then you can type the char ) to close the batch of commands and then it will execute automatically.

@Yzöwl

Nice to see the wise owl is still flying around.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...