Solved

EXECUTE DOS COMMAND

Posted on 2000-03-20
5
320 Views
Last Modified: 2010-04-16
HOW TO EXECUTE A DOS COMMAND E.G. DEL
IN PASCAL ?
0
Comment
Question by:adrianmak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
bakry99 earned 10 total points
ID: 2638908
{$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
ID: 2642703
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
ID: 2643310
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
ID: 2644667
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
ID: 2644674
Opps !!!

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

      should be read as

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

Sorry for the typo... :(
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why do some people recommend buying business VoIP from an ISP? What are the benefits to my company? What are the costs?
This article describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 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