Solved

Create Process

Posted on 2004-05-02
4
450 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now