Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

EXECUTE DOS COMMAND

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Steps to fix error: “Couldn’t mount the database that you specified. Specified database: HU-DB; Error code: An Active Manager operation fail”
Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

963 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