Running a batch or EXE file from a TP program 
Author Message
 Running a batch or EXE file from a TP program

I have been trying to produce a program which copies files from HD to
floppy (for backup) and runs a batch file when it is quit.  However,
I'm not sure how to do this.  I tried the EXEC command from DOS.TPU but
that doesn't work.  I would be grateful if anyone can solve this
problem.

--

<       U O      |_|_|_|_|_|    O  ||       WWW:   http://www.*-*-*.com/
 \,     |/|\      _________       [  ]            
     .  |/^\  .       2       .   /__\
...In the middle ages, witches were burned.  Now they become famous



Wed, 18 Jun 1902 08:00:00 GMT  
 Running a batch or EXE file from a TP program

Quote:
> I have been trying to produce a program which copies files from HD to
> floppy (for backup) and runs a batch file when it is quit.  However,
> I'm not sure how to do this.  I tried the EXEC command from DOS.TPU but
> that doesn't work.  I would be grateful if anyone can solve this
> problem.

   It's awfully hard to solve a problem which shouldn't be if you had
done all the proper things.  In the absence of knowing what error(s) you
got (when the Exec didn't work) or seeing your code, it's futile to even
guess what you might have done wrong or left out of your implementation.  
I'd like to help, but I cannot do so with nothing to work with...


Wed, 18 Jun 1902 08:00:00 GMT  
 Running a batch or EXE file from a TP program

Stephen Crocker schrieb:

Quote:
> I have been trying to produce a program which copies files from HD to
> floppy (for backup) and runs a batch file when it is quit.  However,
> I'm not sure how to do this.  I tried the EXEC command from DOS.TPU but
> that doesn't work.  I would be grateful if anyone can solve this
> problem.

First try to reduce your memory requirements with the $M ---- switch sothat there
is enough memory for the COMMAND.COM.SwapVectors;Exec(GetEnv('COMSPEC'),'/C COPY
'+sourcefilespec+' A:');
SwapVectors;

This should work
Franz Glaser, Austria   please visit my URL
http://members.eunet.at/meg-glaser



Wed, 18 Jun 1902 08:00:00 GMT  
 Running a batch or EXE file from a TP program


1998 09:39:05 in comp.lang.Pascal.borland, Stephen Crocker

Quote:

>I have been trying to produce a program which copies files from HD to
>floppy (for backup) and runs a batch file when it is quit.  However,
>I'm not sure how to do this.  I tried the EXEC command from DOS.TPU but
>that doesn't work.  I would be grateful if anyone can solve this
>problem.

To run a batch file *after* your program quits, get your program to
insert the command <batchfilename> into the typeahead buffer, with
Int 16/05 (for which see Ralf's List, for which see pas-linx.htm or
pc-urls.htm via the sig URL; and see TSFAQP #120.

To run a batch file *before* your program quits, remember that a
(new) copy of command.com (or ...) is needed; see TSFAQP #9 :  
       write ('Directory call from within TP by Timo Salmi');
       SwapVectors;
       Exec (GetEnv('comspec'), '/c dir *.*');  (* Execution *)
       SwapVectors;
       (* Testing for errors is recommended *)
       if DosError <> 0 then
         writeln ('Dos error number ', DosError)
       else
         writeln ('Mission accomplished, exit code ', DosExitCode);
       (* For DosError and DosExitCode details see the TP manual *)

If you don't know about TSFAQP, read this group regularly, or see
pascal.htm#Timo via below.

Don't post to comp.lang.pascal; it does not exist, as you should know
if you were a regular reader of this group.

--

  Web <URL: http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
  Correct 4-line sig separator is as above, a line comprising "-- " (SoRFC1036)
  Do not Mail News to me.    Before a reply, quote with ">" or "> " (SoRFC1036)



Wed, 18 Jun 1902 08:00:00 GMT  
 Running a batch or EXE file from a TP program

Quote:

> I have been trying to produce a program which copies files from HD to
> floppy (for backup) and runs a batch file when it is quit.  However,
> I'm not sure how to do this.  I tried the EXEC command from DOS.TPU but
> that doesn't work.  I would be grateful if anyone can solve this
> problem.

Reading through other replies here posted so far, I'm not sure the answer has
quite been addressed.  When you call exec(), the program you call has to be
actual binary program code, as an .EXE or .COM.  A .BAT file is essentially a
text script which needs to be read by something -- specifically the DOS
commmand-line processor.  If you load it directly, the DOS code behind exec()
assumes you're feeding it a binary executable, and it's natural response is to
{*filter*}on it and hang.

Just call your .BAT file via the command shell, and you won't have a problem:

  swapvectors;
  exec (getenv('COMSPEC'),'/c somebat.bat')'
  swapvectors;

There's another soluton possible which uses the keyboard buffer and BIOS, but
IMHO it's not 100% reliable for something like this and takes away the
potential error checking that a call to exec() would provide -- that
considered, I won't go any further with that idea.

Quote:
> --

> <       U O      |_|_|_|_|_|    O  ||       WWW:   http://www.*-*-*.com/
>  \,     |/|\      _________       [  ]
>      .  |/^\  .       2       .   /__\
> ...In the middle ages, witches were burned.  Now they become famous

--
Scott Earnest            | SPAM protection in effect. Remove  |





Wed, 18 Jun 1902 08:00:00 GMT  
 Running a batch or EXE file from a TP program

Quote:

> I have been trying to produce a program which copies files from HD to
> floppy (for backup) and runs a batch file when it is quit.  However,
> I'm not sure how to do this.  I tried the EXEC command from DOS.TPU but
> that doesn't work.  I would be grateful if anyone can solve this
> problem.

> --

> <       U O      |_|_|_|_|_|    O  ||       WWW:   http://www.crok.demon.co.uk
>  \,     |/|\      _________       [  ]
>      .  |/^\  .       2       .   /__\
> ...In the middle ages, witches were burned.  Now they become famous

what you need is folowing:

        SwapVectors;
        Exec('<what ever you need for a command>','<command parameters>'
        SwapVectors;
        if DOSExitCode= ...

--
... Backup not found: (A)bort (R)etry (S)lap nearest innocent bystander.



Wed, 18 Jun 1902 08:00:00 GMT  
 Running a batch or EXE file from a TP program

Quote:


>> I have been trying to produce a program which copies files from HD to
>> floppy (for backup) and runs a batch file when it is quit.  However,
>> I'm not sure how to do this.  I tried the EXEC command from DOS.TPU but
>> that doesn't work.  I would be grateful if anyone can solve this
>> problem.

>> --
>>  x^      ( )      _________         //     Email:


Quote:
>> <       U O      |_|_|_|_|_|    O  ||       WWW:

http://www.crok.demon.co.uk

Quote:
>>  \,     |/|\      _________       [  ]
>>      .  |/^\  .       2       .   /__\
>> ...In the middle ages, witches were burned.  Now they become famous
>what you need is folowing:

> SwapVectors;
> Exec('<what ever you need for a command>','<command parameters>');
> SwapVectors;
> if DOSExitCode= ...

>--
>... Backup not found: (A)bort (R)etry (S)lap nearest innocent bystander.

That's totaly true. But with this program you can't run batch files, because
you need
executable files not scripts. You must do something like this:

SwapVectors;
Exec('COMMAND.COM', '/C <batch file>');
SwapVectors;



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. How do I run a batch file in TP 6 using EXEC

2. Executing DOS batch files (or any other program files) and deleting files with PASCAL

3. Running External EXE files from a program [EXEC]

4. Running .EXE files from program

5. Running a BATCH program from pascal

6. Query: How to tell if .EXE being called from a batch file

7. How run a program.exe at the end of a pascal program

8. Executing a batch program from TP

9. Using Pascal to run batch files

10. Running batch file with exec

11. BATCH files won't run!! :-(

12. running windows exe programs from Turbo Pascal

 

 
Powered by phpBB® Forum Software