LLVM API Documentation

Program.h

Go to the documentation of this file.
00001 //===- llvm/System/Program.h ------------------------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by Reid Spencer and is distributed under the
00006 // University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares the llvm::sys::Program class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_SYSTEM_PROGRAM_H
00015 #define LLVM_SYSTEM_PROGRAM_H
00016 
00017 #include "llvm/System/Path.h"
00018 #include <vector>
00019 
00020 namespace llvm {
00021 namespace sys {
00022 
00023   /// This class provides an abstraction for programs that are executable by the
00024   /// operating system. It provides a platform generic way to find executable
00025   /// programs from the path and to execute them in various ways. The sys::Path
00026   /// class is used to specify the location of the Program.
00027   /// @since 1.4
00028   /// @brief An abstraction for finding and executing programs.
00029   class Program {
00030     /// @name Methods
00031     /// @{
00032     public:
00033       /// This static constructor (factory) will attempt to locate a program in
00034       /// the operating system's file system using some pre-determined set of
00035       /// locations to search (e.g. the PATH on Unix).
00036       /// @returns A Path object initialized to the path of the program or a
00037       /// Path object that is empty (invalid) if the program could not be found.
00038       /// @throws nothing
00039       /// @brief Construct a Program by finding it by name.
00040       static Path FindProgramByName(const std::string& name);
00041 
00042       /// This function executes the program using the \p arguments provided and
00043       /// waits for the program to exit. This function will block the current
00044       /// program until the invoked program exits. The invoked program will
00045       /// inherit the stdin, stdout, and stderr file descriptors, the
00046       /// environment and other configuration settings of the invoking program.
00047       /// If Path::executable() does not return true when this function is
00048       /// called then a std::string is thrown.
00049       /// @param path A sys::Path object providing the path of the program to be
00050       /// executed. It is presumed this is the result of the FindProgramByName
00051       /// method.
00052       /// @returns an integer result code indicating the status of the program.
00053       /// A zero or positive value indicates the result code of the program. A
00054       /// negative value is the signal number on which it terminated.
00055       /// @throws std::string on a variety of error conditions or if the invoked
00056       /// program aborted abnormally.
00057       /// @see FindProgrambyName
00058       /// @brief Executes the program with the given set of \p args.
00059       static int ExecuteAndWait(
00060         const Path& path,  ///< The path to the program to execute
00061         const char** args, ///< A vector of strings that are passed to the
00062           ///< program.  The first element should be the name of the program.
00063           ///< The list *must* be terminated by a null char* entry.
00064         const char ** env = 0, ///< An optional vector of strings to use for
00065           ///< the program's environment. If not provided, the current program's
00066           ///< environment will be used.
00067         const sys::Path** redirects = 0, ///< An optional array of pointers to
00068           ///< Paths. If the array is null, no redirection is done. The array
00069           ///< should have a size of at least three. If the pointer in the array
00070           ///< are not null, then the inferior process's stdin(0), stdout(1),
00071           ///< and stderr(2) will be redirected to the corresponding Paths.
00072         unsigned secondsToWait = 0 ///< If non-zero, this specifies the amount
00073           ///< of time to wait for the child process to exit. If the time
00074           ///< expires, the child is killed and this call returns. If zero,
00075           ///< this function will wait until the child finishes or forever if
00076           ///< it doesn't.
00077       );
00078   };
00079 }
00080 }
00081 
00082 
00083 #endif