--- Received from FPU.WHITES1 799 3703 21-12-01 11:44
----------------
-> [EMAIL PROTECTED]
-> [EMAIL PROTECTED]
I'm not familiar with the THandleStream (I guess you're using Borland...?) but doesn't
it allow
you to send data straight to the stream? All your attempts are aimed at talking to php
externally.
Does THandleStream provide something that will let you do:
InStream->Write("0x1A");
...or is the InStream automatically closing when the pipe data finishes.
I'd be much more inclined to insert this into the same pipe rather than coming at it
from the
outside (which probably won't work anyway now you've redirected stdin/stdout).
Alternatively you could just write an intermediate proxy executable that takes charge
of talking
to PHP and can add the CTRLZ itself:
YourProg--[data]-->proxy--[data+CTRLZ]-->PHP
-Steve
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Date: Fri, 21 Dec 2001 12:33:30 +0100
Subject: [PHP-WIN] Send CTRL + Z ( EOF ) key to a PHP (console) program created with
CreateProcess
Hi to all,
I've a question to ask you.
I've do a function which interface PHP.EXE and redirect the stdin / stdout
so I can pass it a TMemoryStream object with stdin and I receive a
TMemoryStream
with stdout. All is done with a console program in which I launch the
PHP.EXE
between the CreateProcess API. The process is hidden so you don't see
never...
At this point I've a problem.
The Pipe don't pass the EOF (CTRL + Z) char to PHP.EXE stdin so I don't able
to inform PHP.EXE of end of my input stdin sequence.
What I must do to do that ?
Follow a snapshot of my C++ code....
Thank you very much....
Silverio Diquigiovanni
bool __fastcall RunPHP(TStream *Input, TStream *Output)
bool Result = false;
// sets security informations
SECURITY_DESCRIPTOR sd;
SECURITY_ATTRIBUTES sa;
LPSECURITY_ATTRIBUTES lpsa = NULL;
if (IsWindowsNT())
{
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, true, NULL, false);
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = true;
sa.lpSecurityDescriptor = &sd;
lpsa = &sa;
}
// creates & checks stdin pipe
HANDLE h_IN_ReadPipe;
HANDLE h_IN_WritePipe;
assert(CreatePipe(&h_IN_ReadPipe, &h_IN_WritePipe, lpsa, 0));
// creates & checks stdout pie
HANDLE h_OUT_ReadPipe;
HANDLE h_OUT_WritePipe;
assert(CreatePipe(&h_OUT_ReadPipe, &h_OUT_WritePipe, lpsa, 0));
// sets process informations
STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof (STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW |STARTF_USESTDHANDLES;
si.wShowWindow = SW_SHOW;
si.wShowWindow = SW_HIDE;
si.hStdInput = h_IN_ReadPipe;
si.hStdOutput = h_OUT_WritePipe;
si.hStdError = h_OUT_WritePipe;
// creates process
bool process_run = CreateProcess
(
NULL,
"PHP.EXE",
NULL,
NULL,
TRUE,
0,
0,
0,
&si,
&pi
);
// checks process running
if (process_run)
{
THandleStream *InStream = new THandleStream((int) h_IN_WritePipe);
Input->Position = 0;
InStream->CopyFrom(Input, Input->Size);
//
// Here I must send the CTRL + Z to the PHP.EXE but I don't know how....
//
/* tentative n.1: no good :(
TerminateProcess(pi.hProcess, 0x1a);
*/
/* tentative n.2: no good :(
HWND CalledHandle = FindWindow(NULL, "PHP");
SendMessage(CalledHandle, 0x0501, 0x1, 0x010d86a4);
*/
/* tentative n.3: no good :(
HWND CalledHandle = FindWindow(NULL, "PHP");
bool b_ok = BringWindowToTop(CalledHandle);
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0);
keybd_event('Z', MapVirtualKey('Z', 0), 0, 0);
keybd_event('Z', MapVirtualKey('Z', 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP,
0);
// Xxx...
WaitForSingleObject(pi.hProcess, INFINITE);
// Xxx...
DWORD BytesRead;
char Buffer[1024];
while (1)
{
memset(Buffer, 0, sizeof (Buffer));
assert
(
ReadFile
(
h_OUT_ReadPipe,
&Buffer,
sizeof (Buffer),
&BytesRead,
NULL
)
);
Output->Write(Buffer, BytesRead);
if (BytesRead < 1024)
break;
}
Result = true;
// frees objects
delete InStream;
CloseHandle(pi.hProcess);
}
// frees objects
CloseHandle(h_IN_ReadPipe);
CloseHandle(h_IN_WritePipe);
CloseHandle(h_OUT_ReadPipe);
CloseHandle(h_OUT_WritePipe);
return Result;
/***************************************************************************
****
* Event handler method
****************************************************************************
***/
void __fastcall TDesktop::RunPHPClick(TObject *Sender)
// creates PHPCode & HTMLCode
TMemoryStream *PHPCode = new TMemoryStream;
TMemoryStream *HTMLCode = new TMemoryStream;
// creates a little PHP script flow
AnsiString s =
(
"<?php" + CRLF +
"echo (\"<br>\n\");" + CRLF +
"for ($a = 1; $a < 6; $a++)" + CRLF +
"{" + CRLF +
"echo (\"Ciao per la $a volta <br>\n\");" + CRLF +
"}" + CRLF +
"exit;" + CRLF +
"?>" + CRLF
);
PHPCode->Write(s.c_str(), s.Length());
// calls & checks PHP html generator
if(::RunPHP(PHPCode, HTMLCode) == true)
{
HTMLCode->SaveToFile("C:\\index.html");
WebBrowser->Navigate((WideString) "C:\\index.html");
}
// frees objects
delete PHPCode;
delete HTMLCode;
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]
This e-mail may contain confidential information and/or copyright
material. This e-mail is intended for the use of the addressee
only. Any unauthorised use may be unlawful.
If you receive this e-mail by mistake please advise the sender
immediately by using the reply facility in your e-mail software.
Friends Provident Marketing Group consists of the following
companies:
Friends Provident Life and Pensions Limited.
Registered number 4096141.
Friends' Provident Unit Trust Managers Limited.
Registered number 970641
FP Life Assurance Limited.
Registered number 782698
Friends Provident Pensions Limited.
Registered number 475201
Friends Ivory & Sime Managed Pensions Funds Limited.
Registered number 1020044
Registered and Head Office of each of the above companies is at Pixham End,
Dorking, Surrey RH4 1QA.
Registered in England. Incorporated companies limited by shares.
Ivory & Sime Trustlink Limited. Registered number 151198
Registered and Head Office: One Charlotte Square, Edinburgh EH2
4DZ. Registered in Scotland. Incorporated company limited by
shares.
Companies within this Group transact life assurance, pension,
permanent health, unit trust and investment trust business
All are regulated by the Financial Services Authority.
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]