Solved

ShellExecute and javac parameters

Posted on 2004-04-17
21
840 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
Independent Software Vendors: 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!

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month8 days, 9 hours left to enroll

615 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