summaryrefslogtreecommitdiff
path: root/examples/OS/Process/process.cpp
blob: 9e901f8317a5985eebe5c8acd3867703f1b74675 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// ============================================================================
// $Id$

//
// = LIBRARY
//    examples
// 
// = FILENAME
//    process.cpp
//
// = DESCRIPTION
//    This example tests the ACE_Process.  For more info, check the
//    README file in this directory.
//
// = AUTHOR
//    Tim Harrison.
// 
// ============================================================================

#include "ace/OS.h"

#include "ace/Process.h"

#if defined (ACE_WIN32)
#define EXEC_NAME "c:\\WINNT35\\system32\\MORE.COM"
#else
#define EXEC_NAME "/usr/bin/cat";
#endif /* ACE_WIN32 */

int
main (int argc, char *argv[])
{
  if (ACE_LOG_MSG->open (argv[0]) == -1)
    ACE_ERROR ((LM_ERROR, "cannot open logger!!!\n"));

  char *executable = argc > 1 ? argv[1] : EXEC_NAME;
  char *input_file = argc > 2 ? argv[2] : "process.cpp";

  ACE_HANDLE infile = ACE_OS::open (input_file, O_RDONLY);

  if (infile == ACE_INVALID_HANDLE)
    ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", input_file), 1);

  static char *l_argv[2]; // Starts out with 0's ;-)
  l_argv[0] = executable;

  // Try to create a new process running the <executable>.
  ACE_Process new_process (l_argv, infile);

  if (ACE_LOG_MSG->op_status () == -1)
    {
      int error = ACE_OS::last_error ();
      ACE_ERROR ((LM_ERROR, "%p errno = %d.\n",
		  executable, error));
    }

  new_process.wait ();
  ACE_OS::close (infile);

  ACE_DEBUG ((LM_DEBUG, "Goodbye.\n"));
  return 42;
}