[PHP-DEV] [Feature] new run() function for php 3.0.15 From: Luca Montecchiani (luca.montecchiani <email protected>)
Date: 03/23/00

Hi all,

We're using php as our standard scripting language
for a new multiplatform application.

Such application will not be a Web based application
and will take advantage about all nice php functions
say ftp,files,crypth,....

We found that php ,due his web oriented nature, lack
of a true system() function that return the exit status
of the called process and forget about his stdout.

We just add a "run()" function that do it in Unix and
Win32 environment, here some examples:

$res = run("notepad.exe");
$res = run("winword.exe &");
$res = run("df");

Comments are welcome, thanks
luca

diff -ur php-3.0.15/functions/basic_functions.c
php-3.0.15.ts/functions/basic_functions.c
--- php-3.0.15/functions/basic_functions.c Wed Feb 23 23:57:21 2000
+++ php-3.0.15.ts/functions/basic_functions.c Wed Mar 22 17:31:46 2000
@@ -224,6 +224,7 @@
  {"system", php3_system, second_arg_force_ref},
  {"escapeshellcmd", php3_escapeshellcmd, NULL},
  {"passthru", php3_passthru, second_arg_force_ref},
+ {"run", php3_run, NULL},

  {"soundex", soundex, NULL},

diff -ur php-3.0.15/functions/exec.c php-3.0.15.ts/functions/exec.c
--- php-3.0.15/functions/exec.c Sun Feb 20 21:42:14 2000
+++ php-3.0.15.ts/functions/exec.c Thu Mar 23 11:56:06 2000
@@ -373,6 +373,58 @@
  efree(cmd);
 }
 /* }}} */
+
+/* {{{ proto int run(string command)
+ * Execute a command and return exit code */
+void php3_run(INTERNAL_FUNCTION_PARAMETERS)
+{
+ int ret;
+ pval *arg1;
+
+#ifdef WIN32
+
+ BOOL wait=TRUE;
+ STARTUPINFO si;
+ PROCESS_INFORMATION pi;
+
+#endif
+
+ if (getParameters(ht, 1, &arg1) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+#ifdef WIN32
+
+ ret = strlen(arg1->value.str.val)-1;
+ if ( arg1->value.str.val[ret] == '&' ) {
+ arg1->value.str.val[ret] = 0;
+ wait=FALSE;
+ }
+
+ memset(&si, 0, sizeof(si));
+ si.cb = sizeof(si);
+ si.dwFlags = STARTF_USESHOWWINDOW;
+ si.wShowWindow = SW_SHOW;
+ ret = -1;
+
+ if ( CreateProcess(NULL,arg1->value.str.val,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi) && wait) {
+ WaitForSingleObject(pi.hProcess,INFINITE);
+ if ( !GetExitCodeProcess(pi.hProcess,&ret) )
+ ret = -1;
+ CloseHandle(pi.hThread);
+ CloseHandle(pi.hProcess);
+ }
+
+#else
+
+ ret = system(arg1->value.str.val);
+
+#endif
+
+ RETURN_LONG(ret);
+}
+/* }}} */
+
 /*
  * Local variables:
  * tab-width: 4
diff -ur php-3.0.15/functions/exec.h php-3.0.15.ts/functions/exec.h
--- php-3.0.15/functions/exec.h Sat Jan 1 05:44:09 2000
+++ php-3.0.15.ts/functions/exec.h Wed Mar 22 17:25:34 2000
@@ -37,6 +37,7 @@
 extern void php3_exec(INTERNAL_FUNCTION_PARAMETERS);
 extern void php3_escapeshellcmd(INTERNAL_FUNCTION_PARAMETERS);
 extern void php3_passthru(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_run(INTERNAL_FUNCTION_PARAMETERS);

 char *_php3_escapeshellcmd(char *);
 #endif /* _EXEC_H */

--
Office: luca.montecchiani <email protected>
Home: http://i.am/m.luca m.luca <email protected>

-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>