• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

execute dos commands

How can I execute a dos command from Delphi

thanks
0
AngelFireMateo
Asked:
AngelFireMateo
1 Solution
 
Mohammed NasmanSoftware DeveloperCommented:
Hello

 you can do that by use WinExcu to open new instance of command.com follow by dos command that u want to use

WinExec('command.com /c dir',sw_ShowNormal);


Best regards
Mohammed Nasman
0
 
AngelFireMateoAuthor Commented:
is there another way????
0
 
moorreesCommented:
Yes there is, this is the dos way ->


//Defines
  char prog[256];
  char *path;
 
//First find the path of the file you want  to execute
   path = searchpath("file.exe");

// create the prog as
   AnsiString command=path;

   int result=spawnlp ( P_NOWAIT,
                        path,
                        path,
                        params,
                        NULL );
  if (result != -1)
  {  Close();
  }
  else
  //something went wrong
}
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
intheCommented:
depends on what command your trying to do,often theres another way ,like instead of dos copy there copyfile() etc..
what command are you trying to use ?
0
 
AngelFireMateoAuthor Commented:
I want  to do it in Delphi not in C
0
 
intheCommented:
do what ?
(i mean what commands in particular?)
0
 
CrazyOneCommented:
Yeah, what is the commands you want to pass? It makes a difference in how you go about doing it.
0
 
kretzschmarCommented:
?

winexec('command.com /c dir /on /p',SW_SHOWNORMAL);

shows the current directory sorted by name pagewise
0
 
AngelFireMateoAuthor Commented:
Thanks a lot that's what I was looking for
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now