0

I'm trying to call a batch on a local machine from another batch. Then I'm trying to start services on a remote computer. Here is my code:

call C:\Oracle\Middleware\user_projects\epm_system\bin\start.bat > SS.log
sc \\OtherMachine start "Service1" >> SS.log
sc \\OtherMachine start "Service2" >> SS.log

I've already confirmed that I can start the services without starting start.bat beforehand. However, when I try to call start.bat using the first line of code, it just closes once that completes without running the last two lines.

Drew Rush
  • 710
  • 5
  • 19
  • Does that mean it doesn't execute the last two lines in the code you've posted above? – Robert Harvey Feb 12 '13 at 17:38
  • Yes, that's what I'm saying. – Drew Rush Feb 12 '13 at 17:39
  • Strange. Does `start.bat` contain an `EXIT` or `GOTO:EOF` command? If it does, you could try changing it to `EXIT /B` http://www.robvanderwoude.com/exit.php – Robert Harvey Feb 12 '13 at 17:51
  • Can't change the batch. Is there any way to call it in a new window so that it closes and let the first keep running? – Drew Rush Feb 12 '13 at 17:56
  • Not if it contains an `EXIT` command. The `EXIT` command apparently kills the entire batch. You would have to write a program, something like this: http://stackoverflow.com/a/361121/102937 – Robert Harvey Feb 12 '13 at 17:58
  • @RobertHarvey What about using `start /wait` instead of call? It should be effectively the same (in this particular instance) but not kill the caller as it runs in separate cmd instance – wmz Feb 12 '13 at 18:07

1 Answers1

1

you can call cmd.exe within your first batch, that will not close it if the second batch contains exit. example:
call.cmd

cmd /c "c:\temp\test.cmd"
echo end of first batch

test.cmd

@echo off
echo test 
exit

result :

C:\temp>call.cmd
test
end of first batch
Loïc MICHEL
  • 24,935
  • 9
  • 74
  • 103
  • I tried this, but it didn't work. Thanks for the advice, though. – Drew Rush Feb 12 '13 at 19:36
  • @DrewRush please provide more details : what's the error ? What's inside start.bat ? – Loïc MICHEL Feb 12 '13 at 19:37
  • Doesn't matter. I bill by the hour so I can only spend so much time on any given problem. I've found another approach that works. Thanks for your time and interest, I'm very grateful. – Drew Rush Feb 12 '13 at 19:38