Solved

redirection in delphi 3

Posted on 1998-07-17
2
223 Views
Last Modified: 2010-04-03
I NEED TO LAUNCH AN .EXE AND GET THE PARAMETERS FROM A FILE THAT IS NEEDED BY THE
EXE.  I'M TRYING TO USE A DOS COMMAND LIKE
MYPROG.EXE < FILENAME.EXT.   THIS IS CALLED REDIRECTION IN DOS, REDIRECTING THE COMMAND LINE KEYBOARD INPUT INTO A FILE.  I NEED TO KNOW HOW TO DO THIS IN DELPHI 3.
I CAN LAUNCH THE PROGRAM USING WINEXEC,SHELLEXECUTE, AND CREATEPROCESS; BUT I CAN'T PASS THE NEEDED PARAMETERS  FOR THAT .EXE.  
0
Comment
Question by:mlgwfis
2 Comments
 
LVL 3

Expert Comment

by:vladika
ID: 1358087
I think you can pass file name as first parameter.
In the program you can read value of first parameter
and open file with name equal parameter's value.
Then read others parameters from this file.

0
 
LVL 8

Accepted Solution

by:
ZifNab earned 200 total points
ID: 1358088
Hi mlgwfis,

Brendan Delumpa of Delphi Corner already gave a solution to this :

.. CreateProcess .....

Okay, while the code above works just fine for executing an application, one my readers pointed out that it doesn't work with programs that
 include a command line argument. Why? Because CreateProcess' first parameter expects a fully qualified program name (path\executable) and
 nothing else! In fact, if you include a command line in that parameter, CreateProcess will do nothing. Yikes! In that case, you have to use the
 second argument. In fact, you can use the second parameter even for just executing a program with no command line. Given that,
 ExecNewprocess would be changed as follows:

 {Supply a fully qualified path name in ProgramName
  and any arguments on the command line. As the help file
  states: "If lpApplicationName is NULL, the first white space-delimited
  token of the command line specifies the module name..." In English,
  the characters before the first space encountered (or if no space is
  encountered as in a single program call) is interpreted as the
  EXE to execute. The rest of the string is the argument line.}
 procedure ExecNewProcess(ProgramName : String);
 var
   StartInfo  : TStartupInfo;
   ProcInfo   : TProcessInformation;
   CreateOK   : Boolean;
 begin

   { fill with known state }
   FillChar(StartInfo,SizeOf(TStartupInfo),#0);
   FillChar(ProcInfo,SizeOf(TProcessInformation),#0);
   StartInfo.cb := SizeOf(TStartupInfo);

   CreateOK := CreateProcess(nil, PChar(ProgramName), nil, nil,False,
               CREATE_NEW_PROCESS_GROUP+NORMAL_PRIORITY_CLASS,
               nil, nil, StartInfo, ProcInfo);

   { check to see if successful }
   if CreateOK then
     //may or may not be needed. Usually wait for child processes
     WaitForSingleObject(ProcInfo.hProcess, INFINITE);
 end;

you can find the whole page : http://www.delumpa.com/dc_main.html

Greetings, Zif.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now