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

x
?
Solved

Create Process

Posted on 2004-05-02
4
Medium Priority
?
486 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 150 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

879 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