[extension / windows] exec without using cmd.exe

From: Date: Sun, 15 Jan 2006 19:19:31 +0000
Subject: [extension / windows] exec without using cmd.exe
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-3413@lists.php.net to get a copy of this message
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/html/_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)

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