Avatar of WRieder
WRiederFlag for South Africa asked on

Execute jar from Delphi

I need to execute the followin from Delph

java -jar "C:\dev\Java\MotolubeExport\dist\MotolubeExport.jar

How please?
Delphi

Avatar of undefined
Last Comment
WRieder

8/22/2022 - Mon
Lukasz Zielinski

try this:

procedure TForm1.Button1Click(Sender: TObject);
var si: TStartupInfo;
    pi: TProcessInformation;
begin
  FillChar(pi, SizeOf(pi), 0);
  FillChar(si, SizeOf(si), 0);
  si.cb := SizeOf(si);
  si.dwFlags := STARTF_USESHOWWINDOW;
  si.wShowWindow := SW_SHOWNORMAL;
  CreateProcess(nil, 'java -jar "C:\dev\Java\MotolubeExport\dist\MotolubeExport.jar', nil, nil, False, CREATE_NEW_CONSOLE, nil, nil, si, pi);
end;

ziolko
ASKER
WRieder

Maybe I should add, that a .bat File exists, which executes normally. My problem however is, that "Createprocess" returns immediately, without waiting for the "Actual Process" to finish, which I need to do, as there are additional tasks to be performed after execution.
ASKER CERTIFIED SOLUTION
Lukasz Zielinski

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Lukasz Zielinski

if you start .bat file that in turn starts java CreateProcess will always return immedietly, if you want to wait for actual process you must strat process directly not via .bat. also note that if you use CreateProcess() with WaitForSingle Object() you'll enter wait state until process terminates not until it's started

ziolko.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
WRieder

Just tried it, but didn't work. Executing the Batch File however, always works.

Kind Regards
Wolfgang
Lukasz Zielinski

do you have java.exe \Windows\system32 directory or in any other directory thats included in PATH?
try also using full path to exe something like this:

CreateProcess(nil, 'C:\windows\system32\java.exe -jar C:\dev\Java\MotolubeExport\dist\MotolubeExport.jar', nil, nil, False, CREATE_NEW_CONSOLE, nil, nil, si, pi);

btw. >>"<< character shouldn't be before C:\..., my mistake

ziolko.
ASKER
WRieder

I don't have java on my System. This is for one of my Clients, who does, and thiat's the content of the Batchfile he is normally executing via an Icon from his Desktop.

Kind Regards
Wolfgang
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Lukasz Zielinski

if you don't have java how you want to test your app?


ziolko.
ASKER
WRieder

I am EMailing the App, which is very small, to my Client, who runs it, and reports back. This is just a One-Liner and it's no hassle.

Kind Regards
Wolfgang
Lukasz Zielinski

yeah but debugging is a hassle and since you have problem I think debugging would be helpfull

ziolko.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER
WRieder

In my stupidity I forgot a Double Quote in the Commandline. However, I am awardiing you the points for your efforts anyway.

Kind Regards
Wolfgang