Batch File Programming

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?

CasseyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
ceb102298Commented:
Try to  check the property close on exit, of the 4 files.
0
 
rmarottaCommented:
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
 
CasseyAuthor Commented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
rmarottaCommented:
Try inserting command.com on the first line of the batch.
0
 
CasseyAuthor Commented:
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
 
johnsmCommented:
What happens if you change the order in which the files run?

What does the first file do? (What is its function?)
0
 
MrNtManCommented:
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
 
vikiingCommented:
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
 
bluepetCommented:
what exactly are you trying to do..?

just curious
bluepet

0
 
MindbenderCommented:
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
 
rmarottaCommented:
Try following one.exe with exit command to force it to complete the batch.

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

Ralph
0
 
CasseyAuthor Commented:
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
 
johnsmCommented:
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
 
CasseyAuthor Commented:
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
 
CasseyAuthor Commented:
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
 
johnsmCommented:
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
 
j_powersCommented:
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
 
Asta CuTechnical consultant & graphic designCommented:
Would a goto work to link them?  A novice learning.
0
 
vikiingCommented:
¿Could you post, please, the three pieces of code where each program ends?

0
 
P_S_PriceCommented:
Try running them from within a Basic Program using Shell
0
 
ssteevesCommented:
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
 
rmarottaCommented:
To bypass the problem here, can you simply "echo" what you want on the screen from your batchfile?
0
 
vikiingCommented:
Anyway, Ralph, there's no reason that justifies that strange behavior on the .BAT   :(

0
 
doindaCommented:
Find out what the executables are doing ?
0
 
ronaldvrCommented:
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
 
vikiingCommented:
>>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
 
CasseyAuthor Commented:
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
 
vikiingCommented:
>>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
 
dramsdenCommented:
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

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
vikiingCommented:
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
 
dramsdenCommented:
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
 
CasseyAuthor Commented:
That solution worked, and it's good enough for me.  Thanks.
0
 
dramsdenCommented:
Wonderful,
Clipper lives (Who needs GUI's)

Regards

DRamsden
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.