Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

EXECUTE DOS COMMAND

Posted on 2000-03-20
5
Medium Priority
?
330 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 30 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

The online market is growing at an unprecedented rate and retail eCommerce sales are expected to reach $4 trillion by 2020. Yet, the profit is not just there for the taking because you have to set yourself apart from the competition.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

670 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