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

Running DOS program from Dellphi

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
  • 4
  • 4
1 Solution
Its simple

ShellExecute (YourForm.Handle, nil, 'c:\dosprogram.exe', 'paramfil.txt',nil, SW_SHOWNORMAL);
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.
R_A_MartinAuthor Commented:
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
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.

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?

R_A_MartinAuthor Commented:


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>.

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.
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:

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.

R_A_MartinAuthor Commented:

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.


R_A_MartinAuthor Commented:
Good result
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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