Question

How to run DOS App From Delphi

Asked by: survedge

Hello,
I have a DOS application (console) that was developed in Fortran in 2006. The application is question driven. About 10-12 questions are asked. Once the program finishes the DOS console is closed are user is taken back to Windows. If changes are needed in the data file then user needs to enter everything again. It becomes very tedious by the second time around. Is there a way to run this application from Delphi? Meaning, being able to see what is asked and then answering, programatically, the questions being asked.

Thanks in advance.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-07 at 11:23:00ID24635603
Tags

Delphi 2009

Topics

Delphi IDE

,

Delphi Components

Participating Experts
2
Points
500
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Delphi or C++
    Wow, what a great resource! I need to decide which program to learn first, either C++, Delphi or even Java. This will be my first foray into the programming field, so I'm a bit scared! My primary interest is in developing cross-platform applications, like with Windows and Lin...
  2. Delphi Disadvantages
    What is the Disadvantage Of Delphi against other language?
  3. Distributing database driven programs (Delphi)
    Hi, I'm new at database programming and have come to the distribution stage. I have no real idea on how to do this. I know you have to install BDE on the recipient machine, but I have never been able to do it. My computer is running XP and Delphi 7 Enterprise, and the recipie...
  4. Delphi
    I need some help with following . I need to modify the codes for our tracking system application which is written in Delphi. it runs on paradox . how do I modify these codes to be able to run on oracle database. or what other information do I need, since I don't know Delphi
  5. FORTRAN DLL - String passing from Delphi
    I am attempting to an array of strings of size 25 with 250 characters each to a Fortran DLL from Delphi. The string does not seem to be read properly on the DLL side. Extra space characters are inserted at the beginning of the 1st and other strings on the DLL side. Any hel...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: gtworekPosted on 2009-08-07 at 11:35:13ID: 25045695

You may read DOS app output using this function:

  function RunDos(DosApp:String):string;
  const
     ReadBuffer = 2400;
  var
   Security : TSecurityAttributes;
   ReadPipe,WritePipe : THandle;
   start : TStartUpInfo;
   ProcessInfo : TProcessInformation;
   Buffer : Pchar;
   BytesRead : DWord;
   Apprunning : DWord;
  begin
   With Security do begin
    nlength := SizeOf(TSecurityAttributes) ;
    binherithandle := true;
    lpsecuritydescriptor := nil;
   end;
   if Createpipe (ReadPipe, WritePipe,
                  @Security, 0) then begin
    Buffer := AllocMem(ReadBuffer + 1) ;
    FillChar(Start,Sizeof(Start),#0) ;
    start.cb := SizeOf(start) ;
    start.hStdOutput := WritePipe;
    start.hStdInput := ReadPipe;
    start.hStdError := WritePipe;
    start.dwFlags := STARTF_USESTDHANDLES +
                         STARTF_USESHOWWINDOW;
    start.wShowWindow := SW_HIDE;
 
    if CreateProcess(nil,
           PChar(DosApp),
           @Security,
           @Security,
           true,
           NORMAL_PRIORITY_CLASS,
           nil,
           nil,
           start,
           ProcessInfo)
    then
    begin
     repeat
      Apprunning := WaitForSingleObject
                   (ProcessInfo.hProcess,100) ;
      Application.ProcessMessages;
     until (Apprunning <> WAIT_TIMEOUT) ;
 
if GetFileSize(ReadPipe,nil)=0
  then
    begin
    result:='-=No output=-'#13#10;
    end
  else
    begin
    result:='';
      Repeat
        BytesRead := 0;
        ReadFile(ReadPipe,Buffer[0], ReadBuffer,BytesRead,nil) ;
        Buffer[BytesRead]:= #0;
        OemToAnsi(Buffer,Buffer) ;
        Result := Result + String(Buffer) ;
      until (BytesRead < ReadBuffer) ;
    end;
   end;
   FreeMem(Buffer) ;
   CloseHandle(ProcessInfo.hProcess) ;
   CloseHandle(ProcessInfo.hThread) ;
   CloseHandle(ReadPipe) ;
   CloseHandle(WritePipe) ;
   end;
  end;
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:

Select allOpen in new window

 

by: 8080_DiverPosted on 2009-08-07 at 11:42:01ID: 25045762

That kind of depends on exactly what you mean by "Meaning, being able to see what is asked and then answering, programatically, the questions being asked."

If you mean, can you have a Delphi app emulate a user answering the questions, then the answer is most probably somewhere between "No." and "Not very easily or gracefully."

However, it is possible to initiate teh app from a Delphi app and then, if the data is stored in a file (of a reasonable nature ;-), bring the data up in the Delphi app for editing.

 

by: gtworekPosted on 2009-08-07 at 11:52:39ID: 25045843

8080_Diver: Why do you like to store output in file? It's better to redirect it to delphi app via pipes as I wrote in my sample.

 

by: 8080_DiverPosted on 2009-08-07 at 12:05:41ID: 25045952

@gtworek

For openers, I was entering my response while you were and you got there first (I, unfortunately, had to deal with a minor work ssue while I was typing ;-).

Then there is the point of the original poster's problem description which included the following "If changes are needed in the data file" . . . which, IMHO, indicates that the Fortran app is probably storing the results in a data file (but, hey, what do I know, right? ;-).

I was addressing the question based upon the information provided.

As for my liking to store output in a file, how the heck do you know what I like to do with data?  FYI, I really prefer to put it in a database but, as previously stated, I was working with the situation as described.

Why is it that you seem to want to pipe the results into memory which could then lead to the data being entirely lost if something happens to the process (e.g. it throws an exception that is less than gracefully handled) or the computer (as in, it loses power) while you are processing the data?  By letting the ForTran app do its thing and sace the data in a file and then letting the Delphi app open the file, if worse comes to worse, the Delphi app can always go back and open the file again without requiring the user to re-enter the responses (which, it seems to me, was the whole point of the original question ;-).

 

by: gtworekPosted on 2009-08-07 at 12:15:36ID: 25046019

Question was: "being able to see what is asked and then answering, programatically, the questions being asked"
If you think data can be lost you can save it from Delphi. There's no problem at all.
I know data can be written to a file, than app can read the file then create output file and so on...
But if you need run the child app and use their input and output - use pipes as described in http://msdn.microsoft.com/en-us/library/aa365139(VS.85).aspx
There's no other good solution unless you have to play with cmd scripts.

 

by: 8080_DiverPosted on 2009-08-07 at 12:31:20ID: 25046153

As I originally stated, "Not very easily or gracefully." ;-)

 

by: survedgePosted on 2009-08-07 at 20:58:58ID: 25048273

Thank you for all responses...Now, to clear things up a bit, the DOS program processes data stored in a text file. This file has a specific format. The DOS program reads the data from the file, adjusts the data while using Least Squares adjustment and then saves the resuls to a completely different file (which my app will display). I will let the DOS program do its thing. I just want to automate the DOS app...make life easier...

Reason to be able to read whatever the DOS app displays...because the DOS app requires a dongle being attached to the LPT port to run. If dongle is missing app ends with a statement to that effect and waits for user input of CR...so I need to be able to catch that and let user know...Also, sometimes the data provided has errors in it and the DOS app will display those errors...again, I need to let the user know what is going on...

Anyhow, I will give a try to what gtworek suggested. I did have some pipes going but I kept running into something and had to shut down D9 every time I tried it.

Again, thank you for your input...much appreciated...

 

by: survedgePosted on 2009-08-07 at 21:57:21ID: 25048390

ok...I tried gtworek's function...issues with OemToAnsi (obsolete)..new function is OemToChar, but this function throws an error (E2010 Incompatible types: 'Char' and 'AnsiChar')...tried to fix but was unable...I ran my app with this line blocked....my app seems to do something, but my app does not want to close anymore until I terminate the DOS app through task manager...BTW, The function provided is very similar to that found in the D9 help document. I did not have any luck (immediate crash) with that one though...

Any ideas as to what I am doing wrong? Or what I need to do next?

Thx....

 

by: gtworekPosted on 2009-08-07 at 22:58:14ID: 25048510

You can remove this line. I'm from the country when strange letters are used and had to play with this in my function ;)

Your DOS app probably is waiting for something. Try to use this app normal way and observe what you have to do to close it. Then try to repeat it from delphi.

You can also prepare simple form with memo, edit and button. Then you can run child app and try to display his output in your memo and give him your edit as the input. This should verify communication witha DOS app is OK. If you are sure about this - we can think about automating interaction.

 

by: survedgePosted on 2009-08-09 at 09:41:40ID: 25054765

Did remove the line but the buffer gets filled up with strnage characters (look chinese)....Will try your suggestion...Thx...

 

by: survedgePosted on 2009-08-12 at 09:34:20ID: 25080339

No luck yet....Delphi app hangs when I try to ReadFile...Task manager does show both apps running (the DOS app and my app).  I will continue trying...Thx all...

 

by: gtworekPosted on 2009-08-12 at 10:15:38ID: 25080718

I don't know your app but maybe it's waiting for something. Did you try with memo/edit control of you app?

 

by: survedgePosted on 2009-08-14 at 05:44:43ID: 25097368

So, I tried something else....somewhere in this site there is a discussion about showing a dow program running inside Delphi...I folloewd suggestions and was able to get the DOS app to show inside my Delphi app....A data button was created so I could feed info through the WritePipe...I do not see anything happening in the DOS app...what is interesting is that I can read from the ReadPipe right after I write to the WritePipe, but I am not able to read what is already there...I did notice the DOS app goes right into asking the useful questions...Now, I can run the DOS app from the command prompt and pipe everything to a text file. That works...the text file gets updated evrytime a questions is asked...so, I would run the DOS app from Delphi with the right piping option and I could read the text file through Delphi to find out what the question is...now the challenge is programmatically answering it...

I am sure I am taking loads of the reader's time and I apologize for that...

 

by: survedgePosted on 2009-08-14 at 10:40:04ID: 25100435

@8080 Diver:

To your initial comment, yes, Delphi emulating user answering questions. Thx...

 

by: survedgePosted on 2009-08-24 at 15:14:28ID: 25173109

Maybe this could be accomplished in C/C++...I have tried and tried in Delphi...time to move to C/C++....Thanks to all who contributed....

 

by: survedgePosted on 2009-08-26 at 07:48:36ID: 25188254

 

by: gtworekPosted on 2009-08-26 at 07:52:37ID: 25188303

Great. And how do you read the result in your app after pushing keys?

 

by: survedgePosted on 2009-09-11 at 04:57:11ID: 25308478

I am working on the interface at this point. I will have to figure that one out once I get there...

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...