You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2012/12/03 21:42:00 UTC

[lucy-commits] [1/2] git commit: refs/heads/master - Enhance redirection features of the OS module.

Updated Branches:
  refs/heads/master b1d930cd7 -> 614c8ad69


Enhance redirection features of the OS module.

*   Add a function to redirect the output of a command to a file.
*   Add a function to capture redirected output from a local command.
    (This function replaces a now-unused `run_local` which did no
    redirection.)
*   Consolidate cmd.exe and Unix shell redirection syntax.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/ca3a7846
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/ca3a7846
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/ca3a7846

Branch: refs/heads/master
Commit: ca3a78465ffda182b694b1b1f24e4fd0465eb1e5
Parents: b1d930c
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Nov 27 16:51:52 2012 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Mon Dec 3 12:39:30 2012 -0800

----------------------------------------------------------------------
 charmonizer/src/Charmonizer/Core/OperatingSystem.c |   47 +++++---------
 charmonizer/src/Charmonizer/Core/OperatingSystem.h |   18 ++++--
 2 files changed, 29 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/ca3a7846/charmonizer/src/Charmonizer/Core/OperatingSystem.c
----------------------------------------------------------------------
diff --git a/charmonizer/src/Charmonizer/Core/OperatingSystem.c b/charmonizer/src/Charmonizer/Core/OperatingSystem.c
index fb9ad9b..c897285 100644
--- a/charmonizer/src/Charmonizer/Core/OperatingSystem.c
+++ b/charmonizer/src/Charmonizer/Core/OperatingSystem.c
@@ -115,54 +115,41 @@ chaz_OS_remove(const char *name) {
 }
 
 int
-chaz_OS_run_local(const char *arg1, ...) {
-    va_list  args;
-    size_t   len     = strlen(chaz_OS.local_command_start) + strlen(arg1);
-    char    *command = (char*)malloc(len + 1);
-    int      retval;
-    char    *arg;
-
-    /* Append all supplied texts. */
-    sprintf(command, "%s%s", chaz_OS.local_command_start, arg1);
-    va_start(args, arg1);
-    while (NULL != (arg = va_arg(args, char*))) {
-        len += strlen(arg);
-        command = (char*)realloc(command, len + 1);
-        strcat(command, arg);
-    }
-    va_end(args);
-
-    /* Run the command. */
-    retval = system(command);
-    free(command);
+chaz_OS_run_local_redirected(const char *command, const char *path) {
+    size_t size = strlen(command) + strlen(chaz_OS.local_command_start) + 20;
+    char *local_command = (char*)malloc(size);
+    int retval;
+    sprintf(local_command, "%s%s", chaz_OS.local_command_start, command);
+    retval = chaz_OS_run_redirected(local_command, path);
+    free(local_command);
     return retval;
 }
 
 int
 chaz_OS_run_quietly(const char *command) {
+    return chaz_OS_run_redirected(command, chaz_OS.dev_null);
+}
+
+int
+chaz_OS_run_redirected(const char *command, const char *path) {
     int retval = 1;
     char *quiet_command = NULL;
-    if (chaz_OS.shell_type == CHAZ_OS_POSIX) {
+    if (chaz_OS.shell_type == CHAZ_OS_POSIX
+        || chaz_OS.shell_type == CHAZ_OS_CMD_EXE
+        ) {
         char pattern[] = "%s > %s 2>&1";
         size_t size = sizeof(pattern)
                       + strlen(command)
-                      + strlen(chaz_OS.dev_null)
+                      + strlen(path)
                       + 10;
         quiet_command = (char*)malloc(size);
-        sprintf(quiet_command, pattern, command, chaz_OS.dev_null);
-    }
-    else if (chaz_OS.shell_type == CHAZ_OS_CMD_EXE) {
-        char pattern[] = "%s > NUL 2> NUL";
-        size_t size = sizeof(pattern) + strlen(command) + 10;
-        quiet_command = (char*)malloc(size);
-        sprintf(quiet_command, pattern, command);
+        sprintf(quiet_command, pattern, command, path);
     }
     else {
         chaz_Util_die("Don't know the shell type");
     }
     retval = system(quiet_command);
     free(quiet_command);
-
     return retval;
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/ca3a7846/charmonizer/src/Charmonizer/Core/OperatingSystem.h
----------------------------------------------------------------------
diff --git a/charmonizer/src/Charmonizer/Core/OperatingSystem.h b/charmonizer/src/Charmonizer/Core/OperatingSystem.h
index 8e5a412..fe936d6 100644
--- a/charmonizer/src/Charmonizer/Core/OperatingSystem.h
+++ b/charmonizer/src/Charmonizer/Core/OperatingSystem.h
@@ -31,12 +31,6 @@ extern "C" {
 int
 chaz_OS_remove(const char *name);
 
-/* Concatenate all arguments in a NULL-terminated list into a single command
- * string, prepend the appropriate prefix, and invoke via system().
- */
-int
-chaz_OS_run_local(const char *arg1, ...);
-
 /* Invoke a command and attempt to suppress output from both stdout and stderr
  * (as if they had been sent to /dev/null).  If it's not possible to run the
  * command quietly, run it anyway.
@@ -44,6 +38,18 @@ chaz_OS_run_local(const char *arg1, ...);
 int
 chaz_OS_run_quietly(const char *command);
 
+/* Capture both stdout and stderr for a command to the supplied filepath.
+ */
+int
+chaz_OS_run_redirected(const char *command, const char *path);
+
+/* Run a command beginning with the name of an executable in the current
+ * working directory and capture both stdout and stderr to the supplied
+ * filepath.
+ */
+int
+chaz_OS_run_local_redirected(const char *command, const char *path);
+
 /* Attempt to create a directory.
  */
 void