Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ShellExecute and javac parameters

Posted on 2004-04-17
21
Medium Priority
?
842 Views
Last Modified: 2010-04-04
This my code:

  MyHandle := Form1.Handle;
  App := 'javac.exe';
  Parameters :='C:\hello.java';
  Directory := 'C:\jdk1.3.1_09\bin';
  ShellExecute(MyHandle,nil, App,Parameters, Directory , SW_SHOW);



i want to write this on shellexecute to get the error compilation log file

javac hello.java 2> err.lst

how can i use the that code to do this? (i think something in the parameters)
and how can i keep the dos screen  from disappearing quickly?
0
Comment
Question by:mis82
[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
  • 9
  • 7
  • 5
21 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10850946

Create bat file

C:\jdk1.3.1_09\bin\javac.exe C:\hello.java 2>err.lst
pause

and execute it in place of javac.exe
0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 10854139
Yes, you have to add it to parameters:

 Parameters :='C:\hello.java 2> err.lst'
-->how can i keep the dos screen  from disappearing quickly?
I suggest to use the JCL SHellExecuteAndWait version as the following:

uses
WIndows, SHellApi

function ShellExecAndWait(const FileName: string; const Parameters: string;
  const Verb: string; CmdShow: Integer): Boolean;
  function PCharOrNil(const S: AnsiString): PAnsiChar;
  begin
    if Length(S) = 0 then
      Result := nil
    else
      Result := PAnsiChar(S);
  end;
var
  Sei: TShellExecuteInfo;
  Res: LongBool;
  Msg: tagMSG;
begin
  FillChar(Sei, SizeOf(Sei), #0);
  Sei.cbSize := SizeOf(Sei);
  Sei.fMask := SEE_MASK_DOENVSUBST  or SEE_MASK_FLAG_NO_UI  or SEE_MASK_NOCLOSEPROCESS or
    SEE_MASK_FLAG_DDEWAIT;
  Sei.lpFile := PChar(FileName);
  Sei.lpParameters := PCharOrNil(Parameters);
  Sei.lpVerb := PCharOrNil(Verb);
  Sei.nShow := CmdShow;
  Result := ShellExecuteEx(@Sei);
  if Result then
  begin
    WaitForInputIdle(Sei.hProcess, INFINITE);
    while (WaitForSingleObject(Sei.hProcess, 10) = WAIT_TIMEOUT) do
    begin
      repeat
        Res := PeekMessage(Msg, Sei.Wnd, 0, 0, PM_REMOVE);
        if Res then
        begin
          TranslateMessage(Msg);
          DispatchMessage(Msg);
        end;
      until (Res = False);
    end;
    CloseHandle(Sei.hProcess);
  end;
end;

and call it as follows:
ShellExecAndWait('C:\jdk1.3.1_09\bin\javac.exe ','C:\hello.java 2>err.lst','Open', SW_SHOW);
0
 

Author Comment

by:mis82
ID: 10854524
hello Ferruccio68
i tried it with err.lst   ...not working
and i tried without it  its oky.
and also the dos window disappearing ...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 10857294
and what about using
 
Winexec('javac hello.java 2> err.lst',SW_SHOW);

or with the full path

WinExec('C:\jdk1.3.1_09\bin\javac.exe C:\hello.java 2>err.lst',SW_SHOW);

0
 

Author Comment

by:mis82
ID: 10857460
Also not working with the 2>err.lst
0
 
LVL 17

Expert Comment

by:mokule
ID: 10857504

What is wrong with my suggestion? Didn't You follow it?
0
 

Author Comment

by:mis82
ID: 10857517
everything is ok  , except the err.lst creation
and also the cmd screen hide quickly
0
 

Author Comment

by:mis82
ID: 10857568
i meen when i use ur code without err.lst it works
and with it the compilation fails
and also the cmd screen pop up and close quickly
0
 

Author Comment

by:mis82
ID: 10857579
mokule
acctually i dont know how to create a batch file
0
 
LVL 17

Expert Comment

by:mokule
ID: 10857627
Open a notepad type

C:\jdk1.3.1_09\bin\javac.exe C:\hello.java 2>err.lst
pause

and save as java.bat

or do You like do it from program?
0
 

Author Comment

by:mis82
ID: 10857669
ok but how can i pass the file name everytime to the bat file?
0
 
LVL 17

Accepted Solution

by:
mokule earned 2000 total points
ID: 10857734
For example. Rewrite bat as follows

C:\jdk1.3.1_09\bin\javac.exe %1 2>%2
pause

and then You should pass parameters

Parameters :='C:\hello.java err.lst';
 
0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 10857768
Just one question: how do you write the command line usually into the dos prompt?
0
 
LVL 17

Expert Comment

by:mokule
ID: 10857832
Ferruccio:
If it was question to me. I didn't understand it. Maybe it's my poor English. Please clarify.
0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 10857846
Sorry mokule, my question was directed to mis82 :)
0
 

Author Comment

by:mis82
ID: 10858160
javac hello.java 2>err.lst

hello.java on c:
and the javac path included in the system path to run it from any level
0
 

Author Comment

by:mis82
ID: 10870035
mokule
also the err.lst ....didnt created
0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 10870261
So try using createprocess directly....

a function from a my application:

function ExecApplication(APPName, CmdLine: String; ShowMode: DWord; WaitToExit: Boolean; Title: PCHAR): DWord;
var StartInfo: TStartupInfo;
  ProcInfo: TProcessInformation;
begin
      try
         FillChar(StartInfo, SizeOf(StartInfo), 0);
              StartInfo.cb:=SizeOf(StartInfo);
              StartInfo.dwFlags:=STARTF_USESHOWWINDOW or STARTF_USESIZE or STARTF_USEPOSITION;
                                StartInfo.wShowWindow:=ShowMode;
              startinfo.lpTitle := title;
                               
       
      if AppName <> '' then
            CreateProcess(PChar(APPName), PChar(CmdLine), nil, nil, False, 0,
                         nil, nil, StartInfo, ProcInfo)
              else
            CreateProcess(nil, PChar(CmdLine), nil, nil, False, 0,
                         nil, nil, StartInfo, ProcInfo);
           
              if WaitToExit then
            WaitForSingleObject(ProcInfo.hProcess, INFINITE);
       
        GetExitCodeProcess(ProcInfo.hProcess, Result);
     
      finally
   
      CloseHandle(ProcInfo.hProcess);
      CloseHandle(ProcInfo.hThread );
 
       end;
end;

And call as ExecApplication('','javac hello.java 2>err.lst',SW_SHOWNORMAL,true,'');
0
 
LVL 17

Expert Comment

by:mokule
ID: 10870646
mis82
I've tested my solution. It works. Maybe You've got some problems with folders.

This is my code:

    ShellExecute(Form1.Handle,nil,'simple.bat','hello.java',nil,SW_SHOW);

This is my simple.bat file:

C:\j2sdk1.4.0_02\bin\javac.exe %1 2>err.lst
pause

This is my err.lst:

error: cannot read: hello.java
1 error
0
 

Author Comment

by:mis82
ID: 10906604
Hello
mokule u r right thx
just another small question

how can i run the compiled java application

i use

c:\java  hello

how can i do it by the batch file?
0
 
LVL 17

Expert Comment

by:mokule
ID: 10906754
Hi

ShellExecute(Form1.Handle,nil,'simple.bat','hello.java hello',nil,SW_SHOW);

simple.bat

C:\j2sdk1.4.0_02\bin\javac.exe %1 2>err.lst
pause
if errorlevel 1 goto _error
C:\j2sdk1.4.0_02\bin\java %2
:_error
pause

----------------------------------------
In command prompt You can enter help to have some help for batch commands
0

Featured Post

Industry Leaders: 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

670 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