2017-03-28 12:41:25 -07:00
|
|
|
#include <iostream>
|
2017-03-23 21:20:26 -07:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2017-03-28 12:41:25 -07:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2017-03-23 21:20:26 -07:00
|
|
|
#include "subprocess.hpp"
|
|
|
|
|
2017-06-09 12:16:59 -07:00
|
|
|
#include "bottles.hpp"
|
2017-03-23 21:20:26 -07:00
|
|
|
#include "launch.hpp"
|
|
|
|
#include "internal/launch.hpp"
|
|
|
|
#include "output.hpp"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace cellar;
|
|
|
|
|
|
|
|
void cellar::launch::launch_program(vector<string> args) {
|
2017-06-09 12:16:59 -07:00
|
|
|
string winepath = bottles::active_bottle.get_config("wine-path");
|
|
|
|
if (winepath == "") { winepath = "wine"; } // lets assume wine is in PATH if there's no config for it
|
|
|
|
// TODO: better support for compiled in defaults (cogrc?)
|
|
|
|
|
|
|
|
args[0] = winepath;
|
2017-04-07 21:37:58 -07:00
|
|
|
launch::popen(args);
|
2017-03-23 21:20:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void cellar::launch::launch_command(int argc, vector<string> args) {
|
|
|
|
if (argc == 1) {
|
|
|
|
output::error("forgot to specify a command");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
launch::launch_program(args);
|
|
|
|
}
|
2017-03-27 16:14:04 -07:00
|
|
|
|
|
|
|
void cellar::launch::popen(string argv) {
|
2017-04-07 21:37:58 -07:00
|
|
|
output::warning("use of deprecated string based function", true);
|
|
|
|
output::statement("launching program: " + argv, true);
|
2017-03-28 12:41:25 -07:00
|
|
|
vector<string> argvsplit;
|
|
|
|
boost::algorithm::split(argvsplit, argv, boost::is_any_of(" "));
|
|
|
|
string exec = argvsplit[0];
|
|
|
|
vector<string> subargv;
|
|
|
|
for (int curarg = 1; curarg < argvsplit.size(); curarg++) {
|
|
|
|
subargv.push_back(argvsplit[curarg]);
|
|
|
|
}
|
|
|
|
auto subproc = subprocess::popen(exec, subargv);
|
|
|
|
cout << subproc.stdout().rdbuf();
|
|
|
|
cerr << subproc.stderr().rdbuf();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cellar::launch::popen(vector<string> argv) {
|
2017-04-07 21:37:58 -07:00
|
|
|
output::statement("launching program: " + boost::algorithm::join(argv, " "), true);
|
2017-03-28 12:41:25 -07:00
|
|
|
string exec = argv[0];
|
|
|
|
vector<string> subargv;
|
|
|
|
for (int curarg = 1; curarg < argv.size(); curarg++) {
|
|
|
|
subargv.push_back(argv[curarg]);
|
|
|
|
}
|
|
|
|
auto subproc = subprocess::popen(exec, subargv);
|
|
|
|
cout << subproc.stdout().rdbuf();
|
|
|
|
cerr << subproc.stderr().rdbuf();
|
2017-03-27 16:14:04 -07:00
|
|
|
}
|