summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorharrison <harrison@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-05-09 06:41:24 +0000
committerharrison <harrison@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-05-09 06:41:24 +0000
commit05014d9804c10682c69240271c3bb6268ddf274a (patch)
tree341425a251a750b793a80813764dc7acddf51ad7
parent93a8d612df8272c41c71915b2368c3023ceafddb (diff)
downloadATCD-05014d9804c10682c69240271c3bb6268ddf274a.tar.gz
Work with new ACE_ProcessEx
-rw-r--r--examples/OS/Process/README41
-rw-r--r--examples/OS/Process/process.cpp49
2 files changed, 71 insertions, 19 deletions
diff --git a/examples/OS/Process/README b/examples/OS/Process/README
index 2c2c801d5df..3a28ed03bd0 100644
--- a/examples/OS/Process/README
+++ b/examples/OS/Process/README
@@ -1,10 +1,33 @@
This example shows how to use ACE_Process to "portably" create new
-processes and set their standard handles (stdin, stdout, and stderr).
-On UNIX, ACE_Process uses fork and exec. On Win32, it uses
-CreateProcess. Since we can set the standard handles, we can mimic
-UNIX pipes on Win32 by building chains of processes.
-
-Run the application by typing ./process [filename]. It creates a new
-process to print the contents of <filename> (default is the name of
-the file "process.cpp") to the main console. So all you should see is
-process.cpp printed to the screen. Not very exciting...
+processes. The ACE_Process_Options class allows applications to
+portably specify path, command-line arguments, environment variable
+values. It also allows applications to set the new process' standard
+handles (stdin, stdout, and stderr). ACE_Process is created with the
+ACE_Process_Options and can be used to perform operations on the
+running process.
+
+Run the application as ./process -u to get all the command-line
+options.
+
+Here's an example output:
+
+lambada:OS/Process> ./process -a
+starting...
+starting...
+Fri May 9 01:01:06 CDT 1997
+date succeeded.
+total 598
+drwxr-xr-x 5 harrison doc 512 May 9 00:47 .
+-rw-r--r-- 1 harrison doc 9330 May 7 23:54 .#process.cpp.4.3
+drwxr-xr-x 4 harrison doc 512 Apr 21 15:32 ..
+drwx------ 2 harrison doc 512 May 8 22:33 .obj
+drwx------ 2 harrison doc 512 May 8 22:33 .shobj
+drwxr-xr-x 2 harrison doc 512 May 8 00:11 CVS
+-rw-r--r-- 1 harrison doc 1717 Oct 21 1996 Makefile
+-rw-r--r-- 1 harrison doc 10048 Oct 21 1996 Process.mak
+-rw-r--r-- 1 harrison doc 44032 Oct 21 1996 Process.mdp
+-rw-r--r-- 1 harrison doc 585 Oct 21 1996 README
+-rwx--x--x 1 harrison doc 212992 May 9 01:00 process
+-rw-r--r-- 1 harrison doc 9960 May 9 01:00 process.cpp
+-rw------- 1 harrison doc 1042 May 9 00:47 process.wst
+
diff --git a/examples/OS/Process/process.cpp b/examples/OS/Process/process.cpp
index 3e865874b7c..e540906381d 100644
--- a/examples/OS/Process/process.cpp
+++ b/examples/OS/Process/process.cpp
@@ -23,8 +23,12 @@
#if defined (ACE_WIN32)
#define EXEC_NAME "c:\\WINNT35\\system32\\MORE.COM"
+const char *DATE_PATH = "c:\\Utils\\bin\\date.exe";
+const char *LS_PATH = "c:\\Utils\\bin\\ls.exe";
#else
-#define EXEC_NAME "cat";
+#define EXEC_NAME "/pkg/gnu/bin/less"
+const char *DATE_PATH = "/usr/bin/date";
+const char *LS_PATH = "/usr/bin/ls";
#endif /* ACE_WIN32 */
static char *executable = EXEC_NAME;
@@ -41,10 +45,11 @@ static int run_tokenizer = 0;
static int
parse_args (int argc, char **argv)
{
- ACE_Get_Opt get_opt (argc, argv, "dlx:p:e:gast");
+ ACE_Get_Opt get_opt (argc, argv, "dlx:p:e:gastu");
int c;
while ((c = get_opt ()) != -1)
+ {
switch (c)
{
case 't':
@@ -74,6 +79,7 @@ parse_args (int argc, char **argv)
case 'g':
get_env = 1;
break;
+ case 'u':
default:
ACE_ERROR_RETURN ((LM_ERROR, "Usage:\n"
"-d print date\n"
@@ -87,6 +93,7 @@ parse_args (int argc, char **argv)
"-a run all (d,l,e \"running\")\n"), -1);
break;
}
+ }
return 0;
}
@@ -126,7 +133,7 @@ static void
test_date (void)
{
ACE_Process_Options options;
- options.path ("c:\\Utils\\bin\\date.exe");
+ options.path (DATE_PATH);
// Try to create a new process running date.
ACE_ProcessEx new_process;
@@ -142,10 +149,29 @@ test_date (void)
ACE_DEBUG ((LM_DEBUG, "date succeeded.\n"));
}
+static void
+test_ls (void)
+{
+ ACE_Process_Options options;
+ options.path (LS_PATH);
+ options.cl_options ("-al");
+
+ ACE_ProcessEx new_process;
+ if (new_process.start (options) == -1)
+ {
+ int error = ACE_OS::last_error ();
+ ACE_ERROR ((LM_ERROR, "%p errno = %d.\n",
+ "test_ls", error));
+ }
+
+ new_process.wait ();
+}
+
+#if defined (ACE_WIN32)
// This is just to test the direct usage of CreateProcess. I use this
// occasionally as a sanity check when ACE_Process breaks.
static void
-test_ls (void)
+win32_test_ls (void)
{
PROCESS_INFORMATION process_info;
STARTUPINFO startup_info;
@@ -198,7 +224,7 @@ test_ls (void)
// since CreateProcess does not allow us to inherit AND add
// environment variables.
static void
-spawn_environment_process (void)
+win32_spawn_environment_process (void)
{
PROCESS_INFORMATION process_info;
STARTUPINFO startup_info;
@@ -288,6 +314,7 @@ spawn_environment_process (void)
ACE_DEBUG ((LM_ERROR, "spawn_environment_process succeeded.\n"));
}
}
+#endif
static void
test_setenv (const char *argv0)
@@ -295,7 +322,7 @@ test_setenv (const char *argv0)
ACE_Process_Options options;
options.setenv ("ACE_PROCESS_TEST", "here's a really large number: %u", 0 - 1);
options.path (argv0);
- options.cl_options ("-d -g");
+ options.cl_options ("-g");
ACE_ProcessEx process;
if (process.start (options) == -1)
{
@@ -351,9 +378,6 @@ main (int argc, char *argv[])
process.wait ();
}
- if (run_ls)
- ::test_ls ();
-
if (run_date)
::test_date ();
@@ -368,8 +392,13 @@ main (int argc, char *argv[])
value == 0 ? "no value" : value));
}
+ if (run_ls)
+ ::test_ls ();
+
+#if defined (ACE_WIN32)
if (environment_string != 0)
- spawn_environment_process ();
+ win32_spawn_environment_process ();
+#endif /* ACE_WIN32 */
if (print_file != 0)
test_more ();