How do I get a batc file to exit?

G

Gonzo

I have a batch file that opens a peice of software, however the command
prompt windows stays open and I want it to exit. thisis an example I run to
open Word, I thought exit would work but it doesn't. If I close Word it
closes the batch file.

cd "c:\program files\microsoft office\office11\"
"C:\Program Files\Microsoft Office\OFFICE11\winword.exe
Exit
 
P

Pegasus \(MVP\)

Gonzo said:
I have a batch file that opens a peice [piece?] of software, however the command
prompt windows stays open and I want it to exit. thisis an example I run to
open Word, I thought exit would work but it doesn't. If I close Word it
closes the batch file.

cd "c:\program files\microsoft office\office11\"
"C:\Program Files\Microsoft Office\OFFICE11\winword.exe
Exit

The command "Exit" is unnecessary. The rest goes like so:

@echo off
cd /d "c:\program files\microsoft office\office11\"
start /b "MS Word" "C:\Program Files\Microsoft Office\OFFICE11\winword.exe"
 
D

Detlev Dreyer

Gonzo said:
I have a batch file that opens a peice of software, however the command
prompt windows stays open and I want it to exit. thisis an example I
run to open Word, I thought exit would work but it doesn't. If I close
Word it closes the batch file.

cd "c:\program files\microsoft office\office11\"
"C:\Program Files\Microsoft Office\OFFICE11\winword.exe
Exit ^ " missing!

When starting the batch file from the command prompt, this example will
close the command prompt window instantly:

@ECHO OFF
start /D"C:\program files\microsoft office\office11" winword.exe
Exit
 
G

Gonzo

Which part does the exit?

Pegasus (MVP) said:
Gonzo said:
I have a batch file that opens a peice [piece?] of software, however the command
prompt windows stays open and I want it to exit. thisis an example I run to
open Word, I thought exit would work but it doesn't. If I close Word it
closes the batch file.

cd "c:\program files\microsoft office\office11\"
"C:\Program Files\Microsoft Office\OFFICE11\winword.exe
Exit

The command "Exit" is unnecessary. The rest goes like so:

@echo off
cd /d "c:\program files\microsoft office\office11\"
start /b "MS Word" "C:\Program Files\Microsoft
Office\OFFICE11\winword.exe"
 
P

Pegasus \(MVP\)

Batch files terminate automatically after executing
the last line of code.


Gonzo said:
Which part does the exit?

Pegasus (MVP) said:
Gonzo said:
I have a batch file that opens a peice [piece?] of software, however
the
command
prompt windows stays open and I want it to exit. thisis an example I
run
to
open Word, I thought exit would work but it doesn't. If I close Word it
closes the batch file.

cd "c:\program files\microsoft office\office11\"
"C:\Program Files\Microsoft Office\OFFICE11\winword.exe
Exit

The command "Exit" is unnecessary. The rest goes like so:

@echo off
cd /d "c:\program files\microsoft office\office11\"
start /b "MS Word" "C:\Program Files\Microsoft
Office\OFFICE11\winword.exe"
 
P

Pegasus \(MVP\)

Detlev Dreyer said:
When starting the batch file from the command prompt, this example will
close the command prompt window instantly:

@ECHO OFF
start /D"C:\program files\microsoft office\office11" winword.exe
Exit

You wrote
start /D"C:\program files\microsoft office\office11" winword.exe rather
than
start /B "C:\program files\microsoft office\office11\winword.exe"
 
D

Detlev Dreyer

Pegasus (MVP) said:
You wrote
start /D"C:\program files\microsoft office\office11" winword.exe
rather than
start /B "C:\program files\microsoft office\office11\winword.exe"

Correct. That syntax works as well as yours, see also "Start /?".

| START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
| ^^^^^^^^
| [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
| [/WAIT] [/B] [command/program]
| ^^^^^^^^^^^^^^^^^
| [parameters]

Just try it out. ;)
 
P

Pegasus \(MVP\)

Detlev Dreyer said:
Pegasus (MVP) said:
You wrote
start /D"C:\program files\microsoft office\office11" winword.exe
rather than
start /B "C:\program files\microsoft office\office11\winword.exe"

Correct. That syntax works as well as yours, see also "Start /?".

| START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
| ^^^^^^^^
| [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
| [/WAIT] [/B] [command/program]
| ^^^^^^^^^^^^^^^^^
| [parameters]

Just try it out. ;)

I was referring to your incorrect /D switch and the extraneous
space before "windword.exe". The command would fail on both
counts.
 
D

Detlev Dreyer

Pegasus (MVP) said:
You wrote
start /D"C:\program files\microsoft office\office11" winword.exe
rather than
start /B "C:\program files\microsoft office\office11\winword.exe"

Correct. That syntax works as well as yours, see also "Start /?".
START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
^^^^^^^^
[/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
[/WAIT] [/B] [command/program]
^^^^^^^^^^^^^^^^^
[parameters]

Just try it out. ;)

I was referring to your incorrect /D switch and the extraneous
space before "windword.exe". The command would fail on both
counts.

Nope. See the syntax for the [/Dpath] switch above and try it out!
 
T

Tom Porterfield

Pegasus said:
START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
^^^^^^^^
[/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
[/WAIT] [/B] [command/program]
^^^^^^^^^^^^^^^^^
[parameters]

Just try it out. ;)

I was referring to your incorrect /D switch and the extraneous
space before "windword.exe". The command would fail on both
counts.

The /D switch is not incorrect, it is used to specify the path. The space
before "winword.exe" is not extraneous, it's how the command is properly
formatted when used correctly as Detlev has done. Like he said, before you
assume it as all wrong "just try it out". For starting a Windows app such
as winword.exe, the /B switch has no effect and is unnecessary.
 
P

Pegasus \(MVP\)

Detlev Dreyer said:
Pegasus (MVP) said:
You wrote
start /D"C:\program files\microsoft office\office11" winword.exe
rather than
start /B "C:\program files\microsoft office\office11\winword.exe"

Correct. That syntax works as well as yours, see also "Start /?".

START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
^^^^^^^^
[/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
[/WAIT] [/B] [command/program]
^^^^^^^^^^^^^^^^^
[parameters]

Just try it out. ;)

I was referring to your incorrect /D switch and the extraneous
space before "windword.exe". The command would fail on both
counts.

Nope. See the syntax for the [/Dpath] switch above and try it out!

You're right - I learnt something new!
 
D

Detlev Dreyer

Pegasus (MVP) said:
You're right - I learnt something new!

Yep, the syntax of the "Start" command (WinXP) had been slightly modified
since Win95 and Win2K.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top