Board index » delphi » Questions, questions, questions....So many questions...Help me please...

Questions, questions, questions....So many questions...Help me please...

Quote
Sparticus wrote:

> Hi, I am curious how I can make my program run a program in dos.  For
> example, while my program isrunning, I want it to format the
> "a:"...how is this possible?  (exec??)

> thanx for taking the time to help me...

> -Ryan

Ryan,
  There is a demo (or should be) somewhere in your Turbo Pascal
directory ( if you have Turbo Pascal) that shows you how to do this.
Here is how I think it is done:

{$M 10000}    {I'm not sure if this is the right compiler directive.
But             what you want to do is not allow your program to use all
                of the availabl memory}

Uses Dos;

begin
  swapvectors;      {this statement is required for this to work.  I            
don't know why}
  Exec('format a:','');

  swapvectors;
end.

I'm not sure if this code exactly will work, it's not tested or
anything, but the Swapvectors is the important thing.  Good luck, and
visit my web sight for lots of source code and links:

http://www.cris.com/~rhinoh/tp.htm
Good Luck!
--
R. Hannay                      
Rhi...@Cris.com
http://www.cris.com/~rhinoh/tp.htm

 

Re:Questions, questions, questions....So many questions...Help me please...


Quote
> > Hi, I am curious how I can make my program run a program in dos.  For
> > example, while my program isrunning, I want it to format the
> > "a:"...how is this possible?  (exec??)

> > thanx for taking the time to help me...

> > -Ryan
>   There is a demo (or should be) somewhere in your Turbo Pascal
> directory ( if you have Turbo Pascal) that shows you how to do this.
> Here is how I think it is done:

> {$M 10000}    {I'm not sure if this is the right compiler directive.
> But             what you want to do is not allow your program to use all
>                 of the availabl memory}

   It's not right: there are 3 parameters to the $M option, and the
control you seek is in the 2nd and 3rd.  The first, Stack, must have
_some_ value, but the others can be 0.  For example:
{$M 8192,0,0}

Quote
> Uses Dos;
> begin
>   swapvectors;      {this statement is required for this to work.  I
> don't know why}

   It's to save the program's interrupt vector settings, in case the
spawned child process changes them - the program could have major
problems when return is made and its interrupt vectors have been
altered.  Thus, it's a good practice to SaveVectors before and after an
Exec call.

Quote
>   Exec('format a:','');

   This won't "cut it", since (1) you have incomplete/incorrect syntax
for both the Exec call and the Format command, and (2) you haven't
accounted for the prompt the Format will give - you'll have to respond Y
or N.
   I suggest you use the following call:

  Exec (GetEnv(;COMSPEC','/C format a: <Yes');

where Yes is a string containing the value 'Y'.

Quote
>   swapvectors;
> end.

> I'm not sure if this code exactly will work, it's not tested or
> anything, but the Swapvectors is the important thing.  Good luck, and
> visit my web sight for lots of source code and links:

   No, it won't work, but it's useful information, nonetheless.  Take a
look at/try my changes.  8<}}

Re:Questions, questions, questions....So many questions...Help me please...


Quote
> Hi, I am curious how I can make my program run a program in dos.  For
> example, while my program isrunning, I want it to format the
> "a:"...how is this possible?  (exec??)

   Exce is the conventional way to run (spawn) a DOS program/command
from within an executing TP/BP program.  Here's a way to do it:

{$M 8192,0,0}  { allow maximum spawn area: no Heap }
...
var Resp : string;
    N    : integer;
...
  Resp := 'Y';  { "yes" to prompt }
  SwapVectors;
  Exec (GetEnv('COMSPEC'),'/C format A: <Resp');
  SwapVectors;
  I := DOSExitCode;
  if I <> 0 then writeln ('DOSExitCode failure: ',I);
  if DOSError <> 0 then writeln ('DOSError failure: ',DOSError);
...
   It would be useful for you to look up all this stuff in the manuals,
since you might encounter difficulties when you actually use it - this
is very safe, but it's not fullproof...

Re:Questions, questions, questions....So many questions...Help me please...


Hi, I am curious how I can make my program run a program in dos.  For
example, while my program isrunning, I want it to format the
"a:"...how is this possible?  (exec??)

thanx for taking the time to help me...

-Ryan

Re:Questions, questions, questions....So many questions...Help me please...


In article <32e57433.1763312@news>, spa...@saenterprises.com says...

Quote

>Hi, I am curious how I can make my program run a program in dos.  For
>example, while my program isrunning, I want it to format the
>"a:"...how is this possible?  (exec??)

>thanx for taking the time to help me...

At the top of the program put something like this in:
{$M $4000}             This allows enough memory to run other programs.

Then, put this in the place where you want to run the program :

  SwapVectors;
  Exec('C:\THEPROG.EXE', 'Parameters go here');
  SwapVectors;

SwapVectors changes the vector table of the program with the ones when your
program started so the program that you exec'd doesn't stuff up your program.  
If you don't know what that means, don't worry, just put it in.

The Exec command takes two parameters, the first is the path to the program and
the program (e.g. C:\DOS\BACKUP.EXE) and the second is the parameters to go to
the program (e.g. /b).  Look at the example for Exec for a sample.

Hope this helps,

Bernard.

Re:Questions, questions, questions....So many questions...Help me please...


Quote
Rob Han wrote:
> {$M 10000}    {I'm not sure if this is the right compiler directive.
> But             what you want to do is not allow your program to use all
>                 of the availabl memory}

{$M stack size, heap min, heap max}  Requires 3 numbers.  Usually heap
min will be 0.  If your program doesn't use any heap (memory allocated
with the new() or getmem() procedures), you can set the heap max to 0.  

Quote

> Uses Dos;

> begin
>   swapvectors;      {this statement is required for this to work.  I
> don't know why}

Why you need it:  At the bottom of memory is a table of 256 interrupt
vectors, used for various system calls.  When a TP program starts up, it
saves some of these interrupts and installs new addresses.  The
swapvectors() procedure before the call to exec() temporarily restores
the original values before the program started, and the call afterward
sets the vectors the TP program requires.  This is meant to minimize
conflicts between the system and the program that's running and helps to
avoid crashes.

Quote
>   Exec('format a:','');

No, you need to specify the program name in the first parameter ONLY,
and the rest of the commandline (called the "tail") in the second
parameter.

You might do this rather:

  exec ('format.com','a:');

The filename extention is important too.  I also followed up to Ryan's
message with a bit of code that demonstrates an even better way to set
up the call to exec().

Quote
> --
> R. Hannay
> Rhi...@Cris.com
> http://www.cris.com/~rhinoh/tp.htm

--
Scott Earnest        | We now return you to our regularly |
set...@ix.netcom.com | scheduled chaos and mayhem. . . .  |

Re:Questions, questions, questions....So many questions...Help me please...


In pascal this works

{$M 10000, 0, 0}

uses dos;

begin
   swapvectors;
      exec(getenv('COMSPEC'), '/C FORMAT.COM A:');
  swapvectors;
end.

Sparticus <spa...@saenterprises.com> wrote in article
<32e57433.1763312@news>...

Quote
> Hi, I am curious how I can make my program run a program in dos.  For
> example, while my program isrunning, I want it to format the
> "a:"...how is this possible?  (exec??)

> thanx for taking the time to help me...

> -Ryan

Re:Questions, questions, questions....So many questions...Help me please...


Quote
Sparticus wrote:
> Hi, I am curious how I can make my program run a program in dos.  For
> example, while my program isrunning, I want it to format the
> "a:"...how is this possible?  (exec??)

You can do this:

program external_format;

{$M 4096,0,0} {small stack, no heap}

uses
  dos;

var
  p : pathstr;

begin
  p := fsearch ('format.com',getenv('PATH'));
  if p='' then
    begin
      writeln ('I can''t find the format program!');
      halt;
    end;
  swapvectors;
  exec (p,'a:'); {runs FORMAT.COM with parameters "a:"}
  swapvectors;
  if DosError<>0 then
    writeln ('FORMAT.COM failed with DOS error code ',DosError,'!');
end.

Quote
> thanx for taking the time to help me...

> -Ryan

--
Scott Earnest        | We now return you to our regularly |
set...@ix.netcom.com | scheduled chaos and mayhem. . . .  |

Re:Questions, questions, questions....So many questions...Help me please...


Quote
Mike Copeland <mrc...@primenet.com> writes:
> var Resp : string;
> ...
>   Resp := 'Y';  { "yes" to prompt }
>   SwapVectors;
>   Exec (GetEnv('COMSPEC'),'/C format A: <Resp');
>   SwapVectors;

Oops... you're passing the Dos command the name of a variable in the program?
Don't think that'll work. Instead, you need to give the name of a file which
contains "Y<CR>". Alternatively, you could try
   Exec (GetEnv('COMSPEC'),'/C echo y|format A:');
But I think, even this won't work because FORMAT asks some questions after
the formatting (volume label, format another one), and if input is redirected,
the questions can't be answered, and this might even hang the system...
You'd have to put answers to all the questions into a file, like
"Y<CR><CR>N<CR>" or similar - or just get another format utility that has a
batch option...

Frank

Re:Questions, questions, questions....So many questions...Help me please...


Quote
> > var Resp : string;
> > ...
> >   Resp := 'Y';  { "yes" to prompt }
> >   SwapVectors;
> >   Exec (GetEnv('COMSPEC'),'/C format A: <Resp');
> >   SwapVectors;
> Oops... you're passing the Dos command the name of a variable in the program?
> Don't think that'll work. Instead, you need to give the name of a file which
> contains "Y<CR>". Alternatively, you could try
>    Exec (GetEnv('COMSPEC'),'/C echo y|format A:');
> But I think, even this won't work because FORMAT asks some questions after
> the formatting (volume label, format another one), and if input is redirected,
> the questions can't be answered, and this might even hang the system...
> You'd have to put answers to all the questions into a file, like
> "Y<CR><CR>N<CR>" or similar - or just get another format utility that has a
> batch option...

   True - on all accounts.  Postings that day were sloppy...8<{{

Other Threads