[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

DELPHI-MSDOS

Posted on 2001-06-11
9
Medium Priority
?
422 Views
Last Modified: 2010-04-06
HOW CAN I CALL A MSDOS PROGRAM FROM DELPHI, FOR EXAMPLE I WANT TO EXECUTE TRACERT FROM DELPHI,
HOW CAN I DO IT?????
0
Comment
Question by:Iamme
[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
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 6177341
Hi Iamme,
somesthing like this
ShellExecute(handle,'open','command','/c c:\tr\tracert.exe ',nil,SW_SHOW);
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6177344
Hi Iamme,
do not forget include ShellApi unit in uses clause.
0
 

Author Comment

by:Iamme
ID: 6177354
tnks.......I'll try it................wait me, and I have you an answer..if you have more examples please send it to me
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6177377
Hello

 try this
WinExec('command.com /c tracert 172.16.3.39',sw_ShowNormal);
0
 

Accepted Solution

by:
djadja earned 400 total points
ID: 6180702
Naughty, naughty - hard coding the command processor! It's really not needed...
Also WinExec is a backwards compatibility function that shouldn't be used according to the help...

However, the following cut down should work fine:

uses ShellAPI;

ShellExecute(Application.Handle,PChar('open'),PChar('c:\tr\tracert.exe'),nil,nil,SW_SHOWNORMAL);
0
 
LVL 17

Expert Comment

by:geobul
ID: 6180893
djadja: the same applies to your answer. PChar is not necessary here because Delphi does it for you. Also, when the app is an exe file, specifying 'open', 'print' or nothing does the same - executes the app.

Here is more complex but flexible way which allows you to wait for the completion of the new app.

function ExecApplication(APPName, CmdLine: String; ShowMode: DWord; WaitToExit: Boolean): DWord;
//executes as well WIN and DOS application
var StartInfo: TStartupInfo;
  ProcInfo: TProcessInformation;
begin
  StartInfo.cb:=SizeOf(StartInfo);
  FillChar(StartInfo, SizeOf(StartInfo), 0);
  StartInfo.dwFlags:=STARTF_USESHOWWINDOW;
  StartInfo.wShowWindow:=ShowMode;
  if AppName<>'' then CreateProcess(PChar(APPName), PChar(CmdLine), nil, nil, False, 0, nil, nil, StartInfo, ProcInfo)
  else CreateProcess(nil, PChar(CmdLine), nil, nil, False, 0, nil, nil, StartInfo, ProcInfo);
  if WaitToExit then WaitForSingleObject(ProcInfo.hProcess, INFINITE);
  GetExitCodeProcess(ProcInfo.hProcess, Result);
  CloseHandle(ProcInfo.hProcess);
  CloseHandle(ProcInfo.hThread );
end;

Usage:
ExecApplication('','c:\tr\tracert.exe',SW_SHOWNORMAL,false);

Regards, Geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 6180946
I would like to mention that it is always better to post comments only because:
- proposing an answer locks the question and removes it from the queue;
- the question becomes out of sight for other experts and the questioner cannot receive different ideas from other people - he has that right, doesn't he?;
- every one problem always has more than one possible solution - let the questioner to decide which one best fits his needs.

Regards, Geo
0
 

Expert Comment

by:djadja
ID: 6181282
>> the same applies to your answer
What do you mean? - I haven't used WinExec or command.com?

Sorry about posting as an answer - I've been picked up on that on another post!

Yep - Delphi will convert constant strings to it's PChar equivalent. It's just I ALWAYS use PChar around the string parameters to show its a DLL function as opposed to a pascal 'local' function.

PS. I think it's missing a WaitForInputIdle...

Taken from Delphi Win32 help..."The calling thread can use the WaitForInputIdle function to wait until the new process has finished its initialization and is waiting for user input with no input pending. This can be useful for synchronization between parent and child processes, because CreateProcess returns without waiting for the new process to finish its initialization. For example, the creating process would use WaitForInputIdle before trying to find a window associated with the new process."
0
 
LVL 17

Expert Comment

by:geobul
ID: 6181530
I mean that every one piece of code can be rewritten another way and it's not a reason to post an answer. As far as you didn't want to, I'm sorry too, forget it.

About your PS: CreateProcess returns the handle of the newly created process which is enough for waiting for its end. I'm not going to find its window handle or to communicate with it. The calling app becomes frozen and inaccesible until the called process is working. This is when the last parameter is 'true' only.

Regards, Geo
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

649 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