Solved

redirection in delphi 3

Posted on 1998-07-17
2
230 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
TServerSocket - file via sendbuf or Text via sendtext ? 1 65
TEMBEDDEDWB how can i change its user agent ? 8 69
Base1 Encode/Decode 3 81
Firemonkey BASS_Init into a thread 17 30
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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