Solved

Batch File Programming

Posted on 1999-01-18
33
399 Views
Last Modified: 2010-04-27
Hello,

I've got a wierd problem happening with a batch file I've written.

I've got 4 separate .EXE files that I want to run one after the other.  So, I created a simple batch file to do this:

Batch File:
  One.exe
  Two.exe
  Three.exe
  Four.exe

When I go to DOS and run this batch file, it runs the first .exe file, and then returns to command prompt.  When I type EXIT to return to windows, it says "Bad command of file name" and immediatly continues to run the other 3 .exe files, and then freezes so I can't even type exit anymore.

Anyone know why?

0
Comment
Question by:Cassey
33 Comments
 

Expert Comment

by:ceb102298
Comment Utility
Try to  check the property close on exit, of the 4 files.
0
 
LVL 9

Expert Comment

by:rmarotta
Comment Utility
Have you tried "calling" the executables so the batch will maintain control?
  call one.exe
  call two.exe
  etc.....
If the proposed answer doesn't solve your problem, please reject it.
Ralph
0
 

Author Comment

by:Cassey
Comment Utility
Sorry.  Both answers didn't help.   To ceb:  All the programs already had that box checked.  
To rmarotta: It does the same thing, exept after it I type EXIT, it runs the other 2 EXE files and then exits, instead of freezing.  But after the first EXE file, it still goes to a command prompt.  From this command prompt, I can do anything.  But as soon as I type Exit, it finishes running the batch file...
Any other ideas?
0
 
LVL 9

Expert Comment

by:rmarotta
Comment Utility
Try inserting command.com on the first line of the batch.
0
 

Author Comment

by:Cassey
Comment Utility
Sorry.  Both answers didn't help.   To ceb:  All the programs already had that box checked.  
To rmarotta: It does the same thing, exept after it I type EXIT, it runs the other 2 EXE files and then exits, instead of freezing.  But after the first EXE file, it still goes to a command prompt.  From this command prompt, I can do anything.  But as soon as I type Exit, it finishes running the batch file...
Any other ideas?
0
 
LVL 1

Expert Comment

by:johnsm
Comment Utility
What happens if you change the order in which the files run?

What does the first file do? (What is its function?)
0
 

Expert Comment

by:MrNtMan
Comment Utility
If you are running a batch file and you want to get it to stop while it is still running try using Ctrl-Break, it should stop the progress of the batch and leave you at a prompt. Also try putting pause statments after each one of the .exe's you are trying to run to see if the batch file is indeed running them correctly.
0
 
LVL 3

Expert Comment

by:vikiing
Comment Utility
It is possible program ONE.EXE is executing a Shell to DOS ?; if so, it would fall to command prompt, enabling you to execute any command, as you say you did; and after that, when you execute an EXIT, control returns to ONE.EXE, which finishes, and then batch file passes control to TWO.EXE, and so on.


0
 
LVL 3

Expert Comment

by:bluepet
Comment Utility
what exactly are you trying to do..?

just curious
bluepet

0
 
LVL 1

Expert Comment

by:Mindbender
Comment Utility
Have you considered using blocks in your batch file, eg:
:one
one.exe
goto end

etc etc

:end

??

I really don't know if this would work, I generally use the choice command anyway in batches which I create, so i do it manually (eg select one.exe then two.exe).

0
 
LVL 9

Expert Comment

by:rmarotta
Comment Utility
Try following one.exe with exit command to force it to complete the batch.

one.exe
exit
two.exe
etc.....

Ralph
0
 

Author Comment

by:Cassey
Comment Utility
Sorry people, nothing has worked yet.  

I've simplified the program to this extreme.  
I wrote 3 programs, and compiled them with Clipper.  
One.exe -> @2,0 SAY "Hello"
Two.exe -> @3,0 SAY "There"
Three.exe -> @4,0 Say "World"

If I run each of these files separatly from DOS, it works.  It just displays HELLO THERE WORLD going down the screen.  

Once I put them in a batch file, the problems begin.  

I tried putting PAUSE after each Call statement, and the first one will not get executed before I get returned to DOS.   As soon as I type EXIT to return to windows, the pause statement occurs.  So, the batch is doing something wrong when I finish running the first program.  However, the second two programs then run consecutively, with no problems.  

After the first program runs, and returns me to DOS, I hit CTRL + Break to end the batch, but nothing happens.  

I switch the order of the batch file, and call Two before I call One, and the same thing happens.   It hangs after the first program call.

Any other ideas?

0
 
LVL 1

Expert Comment

by:johnsm
Comment Utility
The problem is probably with clipper. Try putting 3 other exe's in a batch file that were not compiled with clipper and see what happens. I used to write a lot of .com and .exe's for DOS. You probably are not exiting your .exe correctly.


0
 

Author Comment

by:Cassey
Comment Utility
Sorry people, nothing has worked yet.  

I've simplified the program to this extreme.  
I wrote 3 programs, and compiled them with Clipper.  
One.exe -> @2,0 SAY "Hello"
Two.exe -> @3,0 SAY "There"
Three.exe -> @4,0 Say "World"

If I run each of these files separatly from DOS, it works.  It just displays HELLO THERE WORLD going down the screen.  

Once I put them in a batch file, the problems begin.  

I tried putting PAUSE after each Call statement, and the first one will not get executed before I get returned to DOS.   As soon as I type EXIT to return to windows, the pause statement occurs.  So, the batch is doing something wrong when I finish running the first program.  However, the second two programs then run consecutively, with no problems.  

After the first program runs, and returns me to DOS, I hit CTRL + Break to end the batch, but nothing happens.  

I switch the order of the batch file, and call Two before I call One, and the same thing happens.   It hangs after the first program call.

Any other ideas?

0
 

Author Comment

by:Cassey
Comment Utility
OK.  Yes, the problem is with Clipper.  I tried three other EXE files, and it worked.   Do you know why Clipper is doing this?  All three of my programs end with RETURN.  That should be how to end the programs should it not?
0
 
LVL 1

Expert Comment

by:johnsm
Comment Utility
I've never used clipper and I don't know how powerful it is (as in how low into the system you can reach) so I'll try and give you as much advise on that as I can. In DOS, at the lowest level you have to tell the OS to release the program with a call to an interrupt. That interrupt is 21 (hex) and the AH register has to have a value of 4C (hex) to end normally.

For example in Assembler you would use:
 
  mov ah,4c   ;Move into the high bits of the A register
               the value 4C (Hex)
  int 21      ;Call the interrupt number 21 to perform the close
 
I don't think you can make interuppt calls with clipper, but somehow you have to tell the operating system to release the program. Either with an 'exit' or 'end' or something. I don't think a simple 'return' will do it.

The use of a 'return' to end a program sounds a little wierd to me. I've always seen returns used as the end of a procedure or the end of a subroutine, but what ever called the procedure or the subroutine still needs to have its own 'end' like;

 Start               (of program shell)
  Proc()             (call your procedure)
   @4,0 Say "World"  (do your stuff)
  Return             (to shell)  
 End                 (or Exit and release back to DOS)

Try finding a different (more finite) way of ending the program.
See what you can find out and let me know.

JSM
 
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 5

Expert Comment

by:j_powers
Comment Utility
You might want to have this question moved to the programming area. They may have an idea what is going on.

If I was to take a guess, I would say that it may be trying to run all three programs at once, confusing it too much.


0
 
LVL 27

Expert Comment

by:Asta Cu
Comment Utility
Would a goto work to link them?  A novice learning.
0
 
LVL 3

Expert Comment

by:vikiing
Comment Utility
¿Could you post, please, the three pieces of code where each program ends?

0
 
LVL 3

Expert Comment

by:P_S_Price
Comment Utility
Try running them from within a Basic Program using Shell
0
 
LVL 1

Expert Comment

by:ssteeves
Comment Utility
Here's all the code contained in the three programs.  Just one line each.

One.exe = @2,0 SAY "Hello"
Two.exe = @3,0 SAY "There"
Three.exe = @4,0 SAY "World"

It's dBase code, and I've tried putting END, EXIT and RETURN at the end of each program.  It will only compile with RETURN at the end, but it doesn't help at all.

I can't really put them in a Basic program, because as I don't have a compiler for Basic, it would defeat my purpose.
0
 
LVL 9

Expert Comment

by:rmarotta
Comment Utility
To bypass the problem here, can you simply "echo" what you want on the screen from your batchfile?
0
 
LVL 3

Expert Comment

by:vikiing
Comment Utility
Anyway, Ralph, there's no reason that justifies that strange behavior on the .BAT   :(

0
 

Expert Comment

by:doinda
Comment Utility
Find out what the executables are doing ?
0
 
LVL 1

Expert Comment

by:ronaldvr
Comment Utility
1: the correct way for a program to end in Clipper is QUIT
2: Return *should* work as well though...;-)
3: have you tried running it after restarting in Dos prompt only?
0
 
LVL 3

Expert Comment

by:vikiing
Comment Utility
>>But after the first EXE file, it still goes to a command
>>prompt.  From this command prompt, I can do anything.  But as
>>soon as I type Exit, it finishes running the batch file...

When you get the first command prompt, execute the command

         MEM /D/P

That will show all resident and running programs. If ONE.EXE (or some other of them) appears in the list, then that program has executed a Shell, and you're working under it. That would explain the reason why, when you execute an EXIT command, batch processing will go on with TWO.EXE

0
 

Author Comment

by:Cassey
Comment Utility
None of the files appear in the mem report, and I tried placing QUIT at the end of each program as well.  Still nothing.  I can't restart in DOS mode, as I'm running NT.
0
 
LVL 3

Expert Comment

by:vikiing
Comment Utility
>>I can't restart in DOS mode, as I'm running NT.

¿Could it perhaps be a NT problem? ¿Have you tried booting from a diskette and working into pure DOS?

0
 
LVL 1

Accepted Solution

by:
dramsden earned 40 total points
Comment Utility
I've had this problem running a KIX script and shelling from it the solution I found was to run the script from an Icon.
It worked Don't know why don't care it worked you could try that.

I would also suggest (If you can ) try running it from a pure DOS pc and see what happens (Oh I've just seen that this has been suggested, still give it a go)

Also I've done a lot of work with Clipper and I can safely say that as long as you have the Exit statment ot will not cause any further problems and will run.
0
 
LVL 3

Expert Comment

by:vikiing
Comment Utility
Dramsden:
>>Also I've done a lot of work with Clipper and I can safely say
>>that as long as you have the Exit statment ot will not cause
>>any further problems and will run.

Steeves:
>>It's dBase code, and I've tried putting END, EXIT and RETURN
>>at the end of each program.  It will only compile with RETURN
>>at the end, but it doesn't help at all.

Hmmm... two opposite answers...
0
 
LVL 1

Expert Comment

by:dramsden
Comment Utility
Weeeeeelllll, I'll bow to other's experience, but if you want I'll have a look at the code for the 4 PRG's an if I can I'll offer suggestions. (I must say that I wouldn't think the code is the problem though as you are able to run each PRG without a batch file.) I am presuming the code is written in Clipper.

I have a question for you though, Assuming the code is in Clipper, could you not amalgimate it and run it as functions from a main.prg thus taking the batchfile out of the equation.

E.G.

Main.prg

#preamble

One()
Two()
Three()
Four()

Quit

Function One

# code

Return

Function Two

#Code

Return

Bla bla bla


0
 

Author Comment

by:Cassey
Comment Utility
That solution worked, and it's good enough for me.  Thanks.
0
 
LVL 1

Expert Comment

by:dramsden
Comment Utility
Wonderful,
Clipper lives (Who needs GUI's)

Regards

DRamsden
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Hello to users to the new age of computers. There are so many products to choose from nowadays that you maybe confused to understand which product is the correct product for you. Let me explain briefly what should be the idea product for your best n…
We recently endured a series of broadcast storms that caused our ISP to shut us down for brief periods of time. After going through a multitude of tests, we determined that the issue was related to Intel NIC drivers on some new HP desktop computers …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now