Solved

Executing program with parameters

Posted on 2002-07-07
4
183 Views
Last Modified: 2010-04-04
Hi,

I'm trying to execute an external program with the shellexecute API. The exteranal program needs rather a lot of parameters in order to run correctly however; i.e. c:\dir\progname.exe -para1 -para2 etc.

How can I do this in Delphi? Idealy my program will generate the parameters at run time.

Thanks,

BTW, the external program is xplanet - a you can find more information at http://xplanet.sourceforge.net. I'm attempting to create a small [simple] launcher for it.
0
Comment
Question by:alza
[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 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 7135532
Hi alza,

look in the help for samples on  paramcount and paramstr for this

HAGD:O)Bruintje
0
 
LVL 34

Accepted Solution

by:
Slick812 earned 50 total points
ID: 7135759
hello alza, you could try something like this -
add ShellApi to your uses clause

implementation

uses ShellApi

var
ExePath, SendParam: String;
begin

  ExePath := 'C:\Folder\Exe.exe'
  SendParam := Param1+' '+Param2+' '+Param3;

  ShellExecute(Handle,
'open',     // pointer to string that specifies operation to perform
    PChar(ExePath),     // pointer to filename or folder name string
    PChar(SendParam),     // pointer to string that specifies executable-file parameters
    nil,     // pointer to string that specifies default directory
    SW_SHOW      // whether file is shown when opened
   );

end;
0
 

Author Comment

by:alza
ID: 7135800
Hello and thank you to you both.

Slick812;
I've implemented a simple edit box where the parameters can be entered and then assigned to a string (SendParam). This seems to work fine at the moment.

bruintje;
I'm not entirley sure how and where the functions you've mentioned come into it. I've tried using paramstr(0) and this just returns the path of my compiled program...

Thanks,
0
 
LVL 1

Expert Comment

by:herr_apfelschnitt
ID: 7136034
paramstr contains parameters that were used to run the current program, where paramstr(0) (the first one) contains the executable name.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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