Home | History | Annotate | Download | only in bit
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef COMMAND_H
     18 #define COMMAND_H
     19 
     20 #include <map>
     21 #include <string>
     22 #include <vector>
     23 
     24 using namespace std;
     25 
     26 struct Command
     27 {
     28     Command(const string& prog);
     29     ~Command();
     30 
     31     void AddArg(const string& arg);
     32     void AddEnv(const string& name, const string& value);
     33 
     34     const char* GetProg() const;
     35     char* const* GetArgv() const;
     36     char* const* GetEnv() const;
     37 
     38     string GetCommandline() const;
     39 
     40     string prog;
     41     vector<string> args;
     42     map<string,string> env;
     43 };
     44 
     45 /**
     46  * Run the command and collect stdout.
     47  * Returns the exit code.
     48  */
     49 string get_command_output(const Command& command, int* err, bool quiet=false);
     50 
     51 /**
     52  * Run the command.
     53  * Returns the exit code.
     54  */
     55 int run_command(const Command& command);
     56 
     57 // Mac OS doesn't have execvpe. This is the same as execvpe.
     58 int exec_with_path_search(const char* prog, char const* const* argv, char const* const* envp);
     59 
     60 #endif // COMMAND_H
     61 
     62