Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

Batch files confusion

- - - - -

  • Please log in to reply
10 replies to this topic

#1
Octopuss

Octopuss

    I am the walrus

  • Member
  • PipPipPipPipPipPip
  • 1,127 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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, 23 June 2013 - 10:41 AM.



How to remove advertisement from MSFN

#2
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,530 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

You're not starting unspecified programs, you're specifying them!

#3
Octopuss

Octopuss

    I am the walrus

  • Member
  • PipPipPipPipPipPip
  • 1,127 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Huh? I have no idea what are you talking about.

#4
Tripredacus

Tripredacus

    K-Mart-ian Legend

  • Super Moderator
  • 9,699 posts
  • OS:Server 2012
  • Country: Country Flag

Donator

Sounds like you said "unspecified programs" but you could have just said "programs" ... :rolleyes:

http://www.computerh...om/starthlp.htm
MSFN RULES | GimageX HTA for PE 3.x | lol probloms
msfn2_zpsc37c7153.jpg

#5
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,530 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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.

#6
Octopuss

Octopuss

    I am the walrus

  • Member
  • PipPipPipPipPipPip
  • 1,127 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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, 24 June 2013 - 02:29 PM.


#7
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,796 posts
  • OS:none specified
  • Country: Country Flag
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

Posted Image


#8
Octopuss

Octopuss

    I am the walrus

  • Member
  • PipPipPipPipPipPip
  • 1,127 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

I would say so, yes.

#9
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,530 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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.

#10
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,796 posts
  • OS:none specified
  • Country: Country Flag
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, 25 June 2013 - 01:34 PM.

Posted Image


#11
MHz

MHz

    Just simple

  • Member
  • PipPipPipPipPipPipPip
  • 1,653 posts
  • OS:Windows 7 x64
  • Country: Country Flag

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN