diff --git a/src-cpp/randomjs/ProgramRunner.cpp b/src-cpp/randomjs/ProgramRunner.cpp
index c7c13fc..73ccabb 100644
--- a/src-cpp/randomjs/ProgramRunner.cpp
+++ b/src-cpp/randomjs/ProgramRunner.cpp
@@ -20,10 +20,12 @@ along with RandomJS. If not, see.
#include "ProgramRunner.h"
#include "Program.h"
#include
+#include
constexpr size_t programBufferCapacity = 256 * 1024;
namespace bp = boost::process;
+namespace bf = boost::filesystem;
void ProgramRunner::startProcess() {
delete runnerStdout;
@@ -39,7 +41,27 @@ void ProgramRunner::startProcess() {
}
}
-ProgramRunner::ProgramRunner(const char* executable, bool searchPath, const char* arguments)
+ProgramRunner::ProgramRunner(const char* self, const char* xs)
+ : stream(programBufferCapacity),
+ arguments(nullptr),
+ runner(nullptr),
+ runnerStdout(nullptr),
+ runnerStdin(nullptr)
+{
+ std::vector searchPaths;
+ auto basedir = bf::system_complete(self).parent_path();
+ searchPaths.push_back(basedir);
+ auto fullPath = bp::search_path(xs, searchPaths);
+ auto pathString = fullPath.string();
+ int allocationSize = pathString.length() + 1;
+ char* pathBuffer = new char[allocationSize];
+ std::copy(pathString.begin(), pathString.end(), pathBuffer);
+ pathBuffer[pathString.length()] = '\0';
+ this->executable = pathBuffer;
+ startProcess();
+}
+
+/*ProgramRunner::ProgramRunner(const char* executable, bool searchPath, const char* arguments)
: stream(programBufferCapacity),
arguments(arguments),
runner(nullptr),
@@ -56,7 +78,7 @@ ProgramRunner::ProgramRunner(const char* executable, bool searchPath, const char
this->executable = executable;
}
startProcess();
-}
+}*/
void ProgramRunner::writeProgram(Program* p) {
stream.clear();
diff --git a/src-cpp/randomjs/ProgramRunner.h b/src-cpp/randomjs/ProgramRunner.h
index 6195f46..e12ff8e 100644
--- a/src-cpp/randomjs/ProgramRunner.h
+++ b/src-cpp/randomjs/ProgramRunner.h
@@ -42,7 +42,8 @@ namespace boost {
class ProgramRunner
{
public:
- ProgramRunner(const char* executable, bool searchPath = false, const char* arguments = nullptr);
+ ProgramRunner(const char* self, const char* xs);
+ //ProgramRunner(const char* executable, bool searchPath = false, const char* arguments = nullptr);
void writeProgram(Program*);
const char* getProgramBuffer() const {
return stream.data();
diff --git a/src-cpp/randomjs/main.cpp b/src-cpp/randomjs/main.cpp
index efa152d..1c4209a 100644
--- a/src-cpp/randomjs/main.cpp
+++ b/src-cpp/randomjs/main.cpp
@@ -47,7 +47,7 @@ int main(int argc, char** argv) {
0xea, 0x00, 0x00, 0x00, 0x00, 0x77, 0xb2, 0x06, 0xa0, 0x2c, 0xa5, 0xb1, 0xd4, 0xce, 0x6b, 0xbf, 0xdf, 0x0a, 0xca,
0xc3, 0x8b, 0xde, 0xd3, 0x4d, 0x2d, 0xcd, 0xee, 0xf9, 0x5c, 0xd2, 0x0c, 0xef, 0xc1, 0x2f, 0x61, 0xd5, 0x61, 0x09
};
- ProgramRunner runner("./xst");
+ ProgramRunner runner(argv[0], "xst");
int* nonce = (int*)(blockTemplate + 39);
RandomGenerator rand;
ProgramFactory pf(rand);