Solved

EXECUTE DOS COMMAND

Posted on 2000-03-20
5
289 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ShowMessage(listview1.itemappearance.Header.text, Item.text) 9 1,564
WebCam and Delphi 2 2,565
SHBrowseForFolder - Preselecting a folder 5 255
add combobox item based on numbers 9 125
We need a new way to communicate time sensitive or critical info.   The best part of my role at xMatters is visiting our clients all over the world to learn about how they operate their businesses, share insights that xMatters has gleaned across…
In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

22 Experts available now in Live!

Get 1:1 Help Now