Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Running DOS program from Dellphi

Posted on 2010-08-21
9
Medium Priority
?
388 Views
Last Modified: 2013-11-22
I have a program which has to be run from the Command prompt passing two file names.  I have in the past just opened a Command window and typed in the program and the two file names and all has been fine.

Now I have a lot of files to process with the program so would like to use ShellExecute etc. from a Delphi 7 program.

Have tried to figure out what to do but nothing seems to work.

Any Ideas
0
Comment
Question by:R_A_Martin
[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
  • 4
  • 4
9 Comments
 

Expert Comment

by:javierjat
ID: 33492479
Its simple

ShellExecute (YourForm.Handle, nil, 'c:\dosprogram.exe', 'paramfil.txt',nil, SW_SHOWNORMAL);
0
 
LVL 3

Expert Comment

by:PeterIngham
ID: 33493916
ShellExecute is the appropriate call to use.
The sample by javierjat should work!!

Can you provide samples of what you have tried to use, maybe we can spot what it is that is stopping them from working.
0
 

Author Comment

by:R_A_Martin
ID: 33494281
The program format I need to use is below:

I need to enter the <source> and <target> file names and press <enter> to accept the default code when I run through DOS, not sure how to do this.


PROTLISP.EXE is a DOS program !

Enter:       PROTLISP -?                for Help

Syntax:      PROTLISP <Source> <Target> -A<CodeKey> -K<Code> -OK

  <Source>   Source File (required)
  <Target>   Target File (required)
  <CodeKey>  String used for coding (optional)
  <Code>     P = Pack
             C = Code (default)
             K = Pack and Code
  -OK        Messages are displayed without request for confirmation (optional)

  Error     :      ERRORCODE  =  255
  Error-free:      ERRORCODE  =    0
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 3

Expert Comment

by:PeterIngham
ID: 33494409
assuming protlist is not on the path and is in the root of c::

ShellExecute (YourForm.Handle, nil, 'c:\protlisp.exe', 'source.txt target.txt',nil, SW_SHOWNORMAL);

When you say you need to press enter - is this after typing the command
 'c:\protlisp.exe source.txt target.txt'
or is it a reply to a subsequent prompt?

If it is a subsequent prompt, then it gets harder as you need to feed a return into the child process stdin.

Do you need to know the sucess/fail state?



0
 

Author Comment

by:R_A_Martin
ID: 33494454
Peter

Thanks.

Yes the enter is in reply to a prompt for a code but I do not need to type in a code just programmatically send an <enter>.

0
 
LVL 3

Expert Comment

by:PeterIngham
ID: 33494511
Feeding in the Return programatically is a little tricky - what about the error code??
I'll need to do some research to give you working code samples.
0
 
LVL 3

Accepted Solution

by:
PeterIngham earned 2000 total points
ID: 33494520
Thinking laterally - it might be easier to create a batch file to do this rather than writing delphi code.
Use an input redirect to feed the return:

Batchfile.bat:
c:\protlisp.exe source1.txt target1.txt <Return.txt
c:\protlisp.exe source2.txt target2.txt <Return.txt
c:\protlisp.exe source3.txt target3.txt <Return.txt

In return.txt, have just a single Return character

This would also lend itself to using file searches etc from the batch file,  error checking etc.

0
 

Author Comment

by:R_A_Martin
ID: 33494539
Peter

Thanks a good idea, I can use Delphi to copy my files to the correct location and then use the .bat file to protect the files, then delphi to copy to their final location.

Regards

Richard
0
 

Author Closing Comment

by:R_A_Martin
ID: 33494543
Good result
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

664 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