Solved

Create Process

Posted on 2004-05-02
4
458 Views
Last Modified: 2010-04-05
In Ms SDK, there is a function createprocess. But I don't know how I can use it in Delphi. Can you give me a example how to use createprocess to get infomation from that command line
c:\php\php.exe c:\test\a.php

a.php

<?php
$a=12;
echo '<html>';
echo $a;
echo '</html>';
?>

In the command, it show out
<html>12</html>

Can I get that information with createprocess?
0
Comment
Question by:AkaZn
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
shaneholmes earned 50 total points
ID: 10972783
CreateProcess  is  function  used  to  start  programmes,  it  gives  you  more  control
then  ShellExcute.  It is not used to get information from the command line, rather used to run and application and pass information through the command line. Although, you have control over thge parameters.

The applications called by ShellExecute will run asynchronously, that
is, the execution of our application continues without waiting to the end
of the application called by ShellExecute.

If we want an application to
execute synchronously, we shouldn't use ShellExecute, but a code like
the following:


Here  is  an  example  of  using  CreateProcess  to  start  notepad.exe,  then  show  some information  return  by  CreateProcess.



procedure  TForm1.CreateNotepad;
var
    startinfo  :  TStartupInfo;
    processinfo  :  TProcessInformation;
begin
    FillChar(startinfo,SizeOf(TStartupInfo),0);
    with  startinfo  do
      begin
          cb  :=  SizeOf(TStartupInfo);
          dwFlags  :=  STARTF_FORCEONFEEDBACK  or  STARTF_FORCEOFFFEEDBACK
      end;

    CreateProcess('C:\windows\notepad.exe',  '',  Nil,  0,  False,
                                              CREATE_DEFAULT_ERROR_MODE    or  CREATE_NEW_PROCESS_GROUP  or
                                              NORMAL_PRIORITY_CLASS,  Nil  ,'c:\windows\desktop',
                                              startinfo,processinfo);
    with  processinfo  do
      begin
        Label1.Caption  :=  'Process  Handle  :  '  +  IntToHex(hProcess,8);
        Label2.Caption  :=  'Thred  Handle  :  '      +  IntToHex(hThread,8);
        Label3.Caption  :=  'Process  ID  :  '          +  IntToHex(dwProcessId,8);
        Label4.Caption  :=  'Thred  ID  :  '              +  IntToHex(dwThreadId,8);
      end;

end;


http://www.delphicorner.f9.co.uk/articles/wapi4.htm
http://www.chami.com/tips/delphi/122096D.html


Shane
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10976629

  AkaZn, it you want to use the so called "command line" from PHP, you don't need CreateProcess API. You need to do this:

  <?
    $cmdLine = genenv("QUERY_STRING");
  ?>
0
 

Author Comment

by:AkaZn
ID: 10983731
Which I want is use Delphi to get information from what the program (php.exe) show in the command line after I run it. I am a newbie at some part so don't laught at me (BTW I am not natural born English speaker too). I have found that if I use >filename the information I want will be written to a file instead of write to the command console. This topic is how to use create process so I will give point to shaneholmes. But can anyone tell me how use shellexcute and createprocess (I have try but Delphi said it can't find the function). I think it is the same as how to include shell32.dll and shell32.lib. Thank you, everyone who helped me.
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10983996

   Yep, it seems that Shane's answer deserves the points. I agree. Well, about the missing functions ... you probably don't put the unit they are declared in uses clause. CreateProcess in declared in Windows unit and it is added by default. ShellExecute is in ShellAPI unit.

    uses ..., ShellAPI;
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

679 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