Solved

EXECUTE DOS COMMAND

Posted on 2000-03-20
5
288 Views
Last Modified: 2010-04-16
HOW TO EXECUTE A DOS COMMAND E.G. DEL
IN PASCAL ?
0
Comment
Question by:adrianmak
  • 2
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
bakry99 earned 10 total points
Comment Utility
{$M 8192,0,0}
uses Dos;
var Command: string[79];
begin
  Write('Enter DOS command: ');
  Readln(Command);
  if Command <> '' then
    Command := '/C ' + Command;
  SwapVectors;
  Exec(GetEnv('COMSPEC'), Command);
   {this function to execute command}
  SwapVectors;
  if DosError <> 0 then
    Writeln('Could not execute COMMAND.COM');
end.
0
 

Author Comment

by:adrianmak
Comment Utility
bakry99

I have tried the code you advise but it cannot do my flavour

I am using NT workstation 4.0
I want to delete a text file

del test.txt

but it cannot when I switch to dos, the file still exist
then I display the error code, it is 8
0
 
LVL 1

Expert Comment

by:bakry99
Comment Utility
Hi
RunTime Error (8) is "Not enough memory"
try to use TPX.exe instead of turbo.exe
or to delete a file try this:
var
 f: file;
 FileName:String;
begin
 FileName:= (*Put your File name here*);
 assign(f,FileName);
 erase(f);
end.
 

   bakry
0
 
LVL 3

Expert Comment

by:vikiing
Comment Utility
If you need to delete a file, you can, you the Erase() procedure:

   Assign(F, 'FILE.TXT');
   {$I-}
   Reset(F);
   {$I+}
   if IOResult <> 0 then
     Writeln('FILE.TXT not found)
                    else begin
     Close(F);
     Erase(F);
   end;

Remember to Assign the file to the handle (in this case, variable F) before Erasing.
0
 
LVL 3

Expert Comment

by:vikiing
Comment Utility
Opps !!!

>>> , you can, you the Erase()

      should be read as

 "you can use the Erase()"...

Sorry for the typo... :(
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
HOW TO: Install and Configure VMware vSphere Hypervisor 6.5 (ESXi 6.5), Step by Step Tutorial with screenshots. From Download, Checking Media, to Completed Installation.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now