Solved

ShellExecute and javac parameters

Posted on 2004-04-17
21
833 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
  • 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 22

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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 22

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 500 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 22

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 22

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 22

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

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…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

770 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