RE: [PECL-DEV] [extension / windows] exec without using cmd.exe

From: Date: Mon, 16 Jan 2006 14:20:11 +0000
Subject: RE: [PECL-DEV] [extension / windows] exec without using cmd.exe
References: 1  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-3414@lists.php.net to get a copy of this message
It's been a while, but if I recall correctly, CreateProcess() has a couple of parameters to facilitate this. One specifies that the new process is to inherit handles from the creating process and the other allows the creating process to specify things like stdin and stdout. A quick glance at MSDN makes me think that you should look at the bInheritHandles and lpStartupInfo parameters to CreateProcess. Good luck! Dave -----Original Message----- From: gerald@phpside.org [mailto:gerald@phpside.org] Sent: Sunday, January 15, 2006 11:20 AM To: pecl-dev@lists.php.net Subject: [PECL-DEV] [extension / windows] exec without using cmd.exe Hello everyone, I'm very new to extension writing & C/C++, reason why I'm here, trying to get some help. Shot version, to see if you can help me. ============================== I'm trying to write an extension for PHP / Windows (as the problem only occurs on Windows) that will provide a function that act _exactly_ like the standard "exec ()" function without using "cmd.exe" to launch the given command. (For security reasons, my provider do not want to enables CMD.exe for the IIS user (new "advanced security option" in Windows 2003 / IIS 6). BTW, The error message is "unable to fork") Now, for thoose who can help me :-) ============================== I've manage to write my first PHP extension to test if I could launch a programm using the "CreateProcess" (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcekernl/h tml/_wcesdk_Win32_CreateProcess.asp) Windows API. Good news for me, it worked :-) Now I'm able to launch "something.exe" from my PHP script, even if IIS do not want me to use "CMD.EXE" (unable to fork error). But (yes, there's always a but), as I'm not that good (let's say I may not be not the worst) in C/C++, I can't figure out how to "get" the stdout output of the program to "returns it" to the PHP script. (I did search google and stuff, but never found what I wanted.... or was not good enought to realise that what I found did match my need) Here is the code I have for now (I hope it's not that bad) : PHP_FUNCTION(exec_nocmd){STARTUPINFO siStartupInfo; PROCESS_INFORMATION piProcessInfo; memset(&siStartupInfo, 0, sizeof(siStartupInfo)); memset(&piProcessInfo, 0, sizeof(piProcessInfo)); siStartupInfo.cb = sizeof(siStartupInfo);char *action= NULL, *parameters= NULL;int action_len= 4, parameters_len=0; if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "ss", &action, &action_len, &parameters, &parameters_len) == FAILURE ) RETURN_FALSE; if(CreateProcess(action, parameters,0,0,FALSE, CREATE_DEFAULT_ERROR_MODE,0,0, &siStartupInfo,&piProcessInfo) == FALSE) { zend_error( E_WARNING, "Unable to execute shell [%s %s]", action, parameters); } else { WaitForSingleObject(piProcessInfo.hProcess, INFINITE); ::CloseHandle(piProcessInfo.hThread); ::CloseHandle(piProcessInfo.hProcess); } } Thanks for any help you may provide. Gérald (who is very very sorry for his english) -- PECL development discussion Mailing List (http://pecl.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.pecl.dev (#3414) next »