Solved

Create Process

Posted on 2004-05-02
4
456 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

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…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 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