1 //===- llvm/System/Program.h ------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the llvm::sys::Program class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SYSTEM_PROGRAM_H
15 #define LLVM_SYSTEM_PROGRAM_H
17 #include "llvm/System/Path.h"
22 /// This class provides an abstraction for programs that are executable by the
23 /// operating system. It provides a platform generic way to find executable
24 /// programs from the path and to execute them in various ways. The sys::Path
25 /// class is used to specify the location of the Program.
27 /// @brief An abstraction for finding and executing programs.
32 /// This static constructor (factory) will attempt to locate a program in
33 /// the operating system's file system using some pre-determined set of
34 /// locations to search (e.g. the PATH on Unix).
35 /// @returns A Path object initialized to the path of the program or a
36 /// Path object that is empty (invalid) if the program could not be found.
38 /// @brief Construct a Program by finding it by name.
39 static Path FindProgramByName(const std::string& name);
41 /// This function executes the program using the \p arguments provided and
42 /// waits for the program to exit. This function will block the current
43 /// program until the invoked program exits. The invoked program will
44 /// inherit the stdin, stdout, and stderr file descriptors, the
45 /// environment and other configuration settings of the invoking program.
46 /// If Path::executable() does not return true when this function is
47 /// called then a std::string is thrown.
48 /// @returns an integer result code indicating the status of the program.
49 /// A zero or positive value indicates the result code of the program. A
50 /// negative value is the signal number on which it terminated.
51 /// @see FindProgrambyName
52 /// @brief Executes the program with the given set of \p args.
53 static int ExecuteAndWait(
54 const Path& path, ///< sys::Path object providing the path of the
55 ///< program to be executed. It is presumed this is the result of
56 ///< the FindProgramByName method.
57 const char** args, ///< A vector of strings that are passed to the
58 ///< program. The first element should be the name of the program.
59 ///< The list *must* be terminated by a null char* entry.
60 const char ** env = 0, ///< An optional vector of strings to use for
61 ///< the program's environment. If not provided, the current program's
62 ///< environment will be used.
63 const sys::Path** redirects = 0, ///< An optional array of pointers to
64 ///< Paths. If the array is null, no redirection is done. The array
65 ///< should have a size of at least three. If the pointer in the array
66 ///< are not null, then the inferior process's stdin(0), stdout(1),
67 ///< and stderr(2) will be redirected to the corresponding Paths.
68 ///< When an empty Path is passed in, the corresponding file
69 ///< descriptor will be disconnected (ie, /dev/null'd) in a portable
71 unsigned secondsToWait = 0, ///< If non-zero, this specifies the amount
72 ///< of time to wait for the child process to exit. If the time
73 ///< expires, the child is killed and this call returns. If zero,
74 ///< this function will wait until the child finishes or forever if
76 unsigned memoryLimit = 0, ///< If non-zero, this specifies max. amount
77 ///< of memory can be allocated by process. If memory usage will be
78 ///< higher limit, the child is killed and this call returns. If zero -
80 std::string* ErrMsg = 0 ///< If non-zero, provides a pointer to a string
81 ///< instance in which error messages will be returned. If the string
82 ///< is non-empty upon return an error occurred while invoking the
85 // These methods change the specified standard stream (stdin or stdout) to
86 // binary mode. They return true if an error occurred
87 static bool ChangeStdinToBinary();
88 static bool ChangeStdoutToBinary();