diff --git a/assets/web/apps.html b/assets/web/apps.html
index 812d5588..9dc6594a 100644
--- a/assets/web/apps.html
+++ b/assets/web/apps.html
@@ -150,6 +150,22 @@
that sleeps indefinitely
+
+
+
Starting Dir
+
+
+ The starting dir that should be passed to the process.
+ Some apps needs this set to find configuration files for example.
+ If not set, will default to the parent directory of the command
+
+
diff --git a/sunshine/process.cpp b/sunshine/process.cpp
index 1d8ece13..b0704d4b 100644
--- a/sunshine/process.cpp
+++ b/sunshine/process.cpp
@@ -11,6 +11,7 @@
#include
#include
+#include
#include "main.h"
#include "utility.h"
@@ -109,14 +110,17 @@ int proc_t::execute(int app_id) {
if(proc.cmd.empty()) {
BOOST_LOG(debug) << "Executing [Desktop]"sv;
placebo = true;
- }
- else if(proc.output.empty() || proc.output == "null"sv) {
- BOOST_LOG(info) << "Executing: ["sv << proc.cmd << ']';
- _process = bp::child(_process_handle, proc.cmd, _env, bp::std_out > bp::null, bp::std_err > bp::null, ec);
- }
- else {
- BOOST_LOG(info) << "Executing: ["sv << proc.cmd << ']';
- _process = bp::child(_process_handle, proc.cmd, _env, bp::std_out > _pipe.get(), bp::std_err > _pipe.get(), ec);
+ } else {
+ boost::filesystem::path start_dir = proc.starting_dir.empty() ?
+ boost::filesystem::path(proc.cmd).parent_path() : boost::filesystem::path(proc.starting_dir);
+ if(proc.output.empty() || proc.output == "null"sv) {
+ BOOST_LOG(info) << "Executing: ["sv << proc.cmd << ']';
+ _process = bp::child(_process_handle, proc.cmd, _env, bp::start_dir(start_dir), bp::std_out > bp::null, bp::std_err > bp::null, ec);
+ }
+ else {
+ BOOST_LOG(info) << "Executing: ["sv << proc.cmd << ']';
+ _process = bp::child(_process_handle, proc.cmd, _env, bp::start_dir(start_dir), bp::std_out > _pipe.get(), bp::std_err > _pipe.get(), ec);
+ }
}
if(ec) {
@@ -275,6 +279,7 @@ std::optional parse(const std::string &file_name) {
auto output = app_node.get_optional("output"s);
auto name = parse_env_val(this_env, app_node.get("name"s));
auto cmd = app_node.get_optional("cmd"s);
+ auto starting_dir = app_node.get_optional("startingDir"s);
std::vector prep_cmds;
if(prep_nodes_opt) {
@@ -312,6 +317,10 @@ std::optional parse(const std::string &file_name) {
ctx.cmd = parse_env_val(this_env, *cmd);
}
+ if(starting_dir) {
+ ctx.starting_dir = parse_env_val(this_env, *starting_dir);
+ }
+
ctx.name = std::move(name);
ctx.prep_cmds = std::move(prep_cmds);
ctx.detached = std::move(detached);
diff --git a/sunshine/process.h b/sunshine/process.h
index 1339b76b..ed0a3200 100644
--- a/sunshine/process.h
+++ b/sunshine/process.h
@@ -34,6 +34,7 @@ struct cmd_t {
* cmd -- Runs indefinitely until:
* No session is running and a different set of commands it to be executed
* Command exits
+ * starting_dir -- the process starting dir. This is required for some games to run properly.
* cmd_output --
* empty -- The output of the commands are appended to the output of sunshine
* "null" -- The output of the commands are discarded
@@ -52,6 +53,7 @@ struct ctx_t {
std::string name;
std::string cmd;
+ std::string starting_dir;
std::string output;
};