Solved

Batch File Programming

Posted on 1999-01-18
33
403 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
ID: 1020646
Try to  check the property close on exit, of the 4 files.
0
 
LVL 9

Expert Comment

by:rmarotta
ID: 1020647
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
ID: 1020648
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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 9

Expert Comment

by:rmarotta
ID: 1020649
Try inserting command.com on the first line of the batch.
0
 

Author Comment

by:Cassey
ID: 1020650
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
ID: 1020651
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
ID: 1020652
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
ID: 1020653
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
ID: 1020654
what exactly are you trying to do..?

just curious
bluepet

0
 
LVL 1

Expert Comment

by:Mindbender
ID: 1020655
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
ID: 1020656
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
ID: 1020657
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
ID: 1020658
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
ID: 1020659
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
ID: 1020660
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
ID: 1020661
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
 
LVL 5

Expert Comment

by:j_powers
ID: 1020662
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
ID: 1020663
Would a goto work to link them?  A novice learning.
0
 
LVL 3

Expert Comment

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

0
 
LVL 3

Expert Comment

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

Expert Comment

by:ssteeves
ID: 1020666
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
ID: 1020667
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
ID: 1020668
Anyway, Ralph, there's no reason that justifies that strange behavior on the .BAT   :(

0
 

Expert Comment

by:doinda
ID: 1020669
Find out what the executables are doing ?
0
 
LVL 1

Expert Comment

by:ronaldvr
ID: 1020670
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
ID: 1020671
>>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
ID: 1020672
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
ID: 1020673
>>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
ID: 1020674
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
ID: 1020675
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
ID: 1020676
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
ID: 1020677
That solution worked, and it's good enough for me.  Thanks.
0
 
LVL 1

Expert Comment

by:dramsden
ID: 1020678
Wonderful,
Clipper lives (Who needs GUI's)

Regards

DRamsden
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Ways to verify USB ports are blocked on 30,000 PCs/laptops 12 138
110V Lasko bladeless fan blows with a burning smell 5 76
Access bios on restart 11 54
M.2 drives 6 24
In the modern office, employees tend to move around the workplace a lot more freely. Conferences, collaborative groups, flexible seating and working from home require a new level of mobility. Technology has not only changed the behavior and the expe…
A clone is a duplicate copy. Sheep have been cloned and maybe someday even people will be cloned, but disk cloning (performed by the hard drive cloning software) is a vital tool used to manage and protect data. Let’s look at what hard drive cloning …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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