Solved

Executing program with parameters

Posted on 2002-07-07
4
185 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

691 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