Board index » delphi » Using the Exec command to run Dos functions.

Using the Exec command to run Dos functions.

Awhile back, before I got my new computer, I couldn't get the following
program to run.

-----------------------------------------------------------------
program child;
{$M $4000,0,0}
uses dos;
begin
exec('command','/c dir/c c:\*.*');
if doserror<>0 then writeln('Dos Error = ',doserror);
end.
--------------------------------------------------------------

When I got my NEW computer, it ran ok. Now it can't. And I get a Dos
Erro
= 2. Dos error 2 is "File not found!". What gives? What file??? I need
the exec function in another program that I'm writing. Can anyone help
me???????????? Thanks in advance.

-Patrick-

 

Re:Using the Exec command to run Dos functions.


Quote
Patrick D. Rockwell wrote:

> Awhile back, before I got my new computer, I couldn't get the following
> program to run.

> -----------------------------------------------------------------
> program child;
> {$M $4000,0,0}
> uses dos;
> begin
> exec('command','/c dir/c c:\*.*');
> if doserror<>0 then writeln('Dos Error = ',doserror);
> end.
> --------------------------------------------------------------

> When I got my NEW computer, it ran ok. Now it can't. And I get a Dos
> Erro
> = 2. Dos error 2 is "File not found!". What gives? What file??? I need
> the exec function in another program that I'm writing. Can anyone help
> me???????????? Thanks in advance.

> -Patrick-

Instead of using
        exec('command','/c dir /c c:\*.*);
try using
        exec(GetEnv('comspec'),'/c dir /c c:\*.*');
or
        exec('c:\command.com','/c dir /c c:\*.*');

--
God's final message to His creation: "We apologize for the
inconvenience"
Devlin Wright, URL: http://www.geocities.com/SiliconValley/Lakes/7568/

Re:Using the Exec command to run Dos functions.


In article <33731ABF.7...@academic.eastdevon.ac.uk>,
Devlin of Borg  <devlin.wri...@academic.eastdevon.ac.uk> wrote:

Quote
>Patrick D. Rockwell wrote:

>> Awhile back, before I got my new computer, I couldn't get the following
>> program to run.

>> -----------------------------------------------------------------
>> program child;
>> {$M $4000,0,0}
>> uses dos;
>> begin
>> exec('command','/c dir/c c:\*.*');
>> if doserror<>0 then writeln('Dos Error = ',doserror);
>> end.
>> --------------------------------------------------------------

>> When I got my NEW computer, it ran ok. Now it can't. And I get a Dos
>> Erro
>> = 2. Dos error 2 is "File not found!". What gives? What file??? I need
>> the exec function in another program that I'm writing. Can anyone help
>> me???????????? Thanks in advance.

>> -Patrick-

>Instead of using
>    exec('command','/c dir /c c:\*.*);
>try using
>    exec(GetEnv('comspec'),'/c dir /c c:\*.*');
>or
>    exec('c:\command.com','/c dir /c c:\*.*');

No no for the second alternative. There is no guarantee that command.com
is in the root. There is not even guarantee that command.com is used as
command processor. The worst thing one can do is to execute command.com
when another command processor is used. Why? Well think what happens
when program overwrites the transient part and the resident part tries
to load it from %comspec% and finds, say, 4Dos.

Osmo

Other Threads