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