How to exec system commands 
Author Message
 How to exec system commands

How do I execute a system command like DEL?
I tried using exec('del', 'somefile.txt'), but it doesn't work.


Wed, 18 Jun 1902 08:00:00 GMT  
 How to exec system commands

Quote:

> How do I execute a system command like DEL?
> I tried using exec('del', 'somefile.txt'), but it doesn't work.

DEL and DIR and COPY and CD etc. are commands built in the
COMMAND.COM (or another shell program, to make all the experts
listening happy). You must invoke COMMAND.COM or - more flexible -
the program which is defined in the COMSPEC variable.

Exec('COMMAND.COM','/C del somefile.txt');
or, as stated above:
Exec(GetEnv('COMSPEC'),'/C del somefile.txt');
The COMSPEC "knows" where COMMAND.COM is on your disk.

More in Timo's FAQ # 9 which you can download from a link
in the TP-links site, page "FAQ":
http://www.geocities.com/SiliconValley/2926/tp.html

Franz Glaser



Wed, 18 Jun 1902 08:00:00 GMT  
 How to exec system commands
Why not try the DOS.TPU procedures????

If you want to DELETE a file try this

Assign(F,FileName);
Reset(F);
Erase(F);    

this will delete the file and its quicker than using Exec(Speed wise)

hope this helps



Wed, 18 Jun 1902 08:00:00 GMT  
 How to exec system commands

Quote:

> How do I execute a system command like DEL?
> I tried using exec('del', 'somefile.txt'), but it doesn't work.

You have to exec the shell:

Exec(GetEnv('COMSPEC'),'/C del *.*');

And don't forget the $M option!

Andras



Wed, 18 Jun 1902 08:00:00 GMT  
 How to exec system commands
Try this:

exec('command.com /c','del anyfile.txt')

Quote:

>How do I execute a system command like DEL?
>I tried using exec('del', 'somefile.txt'), but it doesn't work.



Wed, 18 Jun 1902 08:00:00 GMT  
 How to exec system commands


Quote:
>If you want to DELETE a file try this

Please don't.

Quote:
>Assign(F,FileName);
>Reset(F);
>Erase(F);    
>this will delete the file and its quicker than using Exec(Speed wise)

It is an error to delete an _open_ file:

Assign(F,FileName);
Erase(F);

Regards
Horst



Wed, 18 Jun 1902 08:00:00 GMT  
 How to exec system commands

Quote:

> Why not try the DOS.TPU procedures????

> If you want to DELETE a file try this

> Assign(F,FileName);
> Reset(F);
> Erase(F);

> this will delete the file and its quicker than using Exec(Speed wise)

> hope this helps

He wanted to execute system commands, not del alone.


Wed, 18 Jun 1902 08:00:00 GMT  
 How to exec system commands
DOS.TPU and CRT.TPU supports most dos system calls
ie, cd, md, rd, del, ren


Wed, 18 Jun 1902 08:00:00 GMT  
 How to exec system commands
Quote:
> Try this:

> exec('command.com /c','del anyfile.txt')

---    ^^^^^^^^^^^^^^^^
   This is a restrictive technique which not everyone can use (i.e. they
may no have "COMMAND.COM" running their system, or it may not be
accessible from where the Exec'd program is executing).  The
documentation (and my experience) suggests using more global code:

  Exec (GetEnv('COMSPEC'),'/C del anyfile.txt')

   Which uses the system variable "COMSPEC" (more available than
"COMMAND.COM") to find the system's command processor and use it to spawn
the child process.

Quote:
> >How do I execute a system command like DEL?
> >I tried using exec('del', 'somefile.txt'), but it doesn't work.



Wed, 18 Jun 1902 08:00:00 GMT  
 How to exec system commands

Quote:
> Why not try the DOS.TPU procedures????

> If you want to DELETE a file try this

> Assign(F,FileName);
> Reset(F);
> Erase(F);    

> this will delete the file and its quicker than using Exec(Speed wise)

yes, it is MUCH faster, but i think i read somewhere in BP help, that file
MUST be closed before erase procedure is called.


Wed, 18 Jun 1902 08:00:00 GMT  
 How to exec system commands
I know "GETENV", but what is $M function? Compiler directive? For what?

--
Sorry for bad english (I'm from Slovenia)!
Matija Polajnar


Quote:

>> How do I execute a system command like DEL?
>> I tried using exec('del', 'somefile.txt'), but it doesn't work.

>You have to exec the shell:

>Exec(GetEnv('COMSPEC'),'/C del *.*');

>And don't forget the $M option!

>Andras



Wed, 18 Jun 1902 08:00:00 GMT  
 How to exec system commands
Quote:
> I know "GETENV", but what is $M function? Compiler directive? For what?

   It controls (allows you to override) the system defaults for Stack,
Heap_Min, and Heap_Max.  Useful for applications using pointers, Exec
calls, deep subprogram nesting/recursion, heavy uses of procedure-local
data, etc.  In short, if you program in TP/BP much, you'll usually find
occasion to use more or less than the standard compiler defaults for
these resources.
Quote:
> >Exec(GetEnv('COMSPEC'),'/C del *.*');
> >And don't forget the $M option!



Wed, 18 Jun 1902 08:00:00 GMT  
 How to exec system commands

Quote:

> I know "GETENV", but what is $M function? Compiler directive? For what?

It is for memory allocation: {$M stack,min,max}
stack: the stack size used by the application
min: the minimum heap size, required by your app
max: the maximum heap size
Default is {$M 16384,0,655360}

If you want to use exec(), you have reduce the memory allocation.
If you don't use the heap, try {$M 16384,0,0}

Quote:
> Sorry for bad english (I'm from Slovenia)!

Never mind.

Andras



Wed, 18 Jun 1902 08:00:00 GMT  
 How to exec system commands
I agree.
I write large menu driven applications for clients.  My main menu program
contains {$M $4000} and each choice on the menu designates a different program
invoked by the exec command.  Without the $M, the main menu program would
consume all of the memory resources leaving none for the "sub" EXE programs.

Jim Culpepper



Wed, 18 Jun 1902 08:00:00 GMT  
 How to exec system commands
I'm so stupid!!!! IN EVERY MY PROGRAM I USING $M (SO PROGRAM DO NOT USE ALL
OF THE FREE MEMORY AND OTHER PROGRAMS CAN RUNNING), AND NOW I ASKING, WHAT
IT IS? AM I NOT STUPID??????

--
Sorry for bad english (I'm from Slovenia)!
Matija Polajnar


Quote:

>> I know "GETENV", but what is $M function? Compiler directive? For what?

>It is for memory allocation: {$M stack,min,max}
>stack: the stack size used by the application
>min: the minimum heap size, required by your app
>max: the maximum heap size
>Default is {$M 16384,0,655360}

>If you want to use exec(), you have reduce the memory allocation.
>If you don't use the heap, try {$M 16384,0,0}

>> Sorry for bad english (I'm from Slovenia)!
>Never mind.

>Andras



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 18 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Pascal Exec command in Windows XP Environment

2. Turbo Pascal 7 Exec Command Trouble

3. exec command whit FPK Pascal

4. the exec command

5. Sending long Command lines to Exec

6. Help: Exec command with TPW 1.5

7. equivalant exec command in BP for BPW

8. Exec command v. Debugger

9. Exec Command problem

10. Exec file, no command.com required?

11. Exec file, no command.com required?

12. EXEC command p/o BP 7.0

 

 
Powered by phpBB® Forum Software