Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ShellExecute and javac parameters

Posted on 2004-04-17
21
Medium Priority
?
846 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

972 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