Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment vars #72

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "deps/winpty"]
path = deps/winpty
url = https://github.com/peters/winpty.git
url = https://github.com/dabretin/winpty.git
2 changes: 1 addition & 1 deletion deps/winpty
36 changes: 14 additions & 22 deletions src/win/pty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ static NAN_METHOD(PtyOpen) {
return NanThrowError("Usage: pty.open(dataPipe, cols, rows, debug)");
}

std::wstring pipeName = to_wstring(String::Utf8Value(args[0]->ToString()));
const wchar_t* pipeName = to_wstring(String::Utf8Value(args[0]->ToString()));
int cols = args[1]->Int32Value();
int rows = args[2]->Int32Value();
bool debug = args[3]->ToBoolean()->IsTrue();
Expand All @@ -196,7 +196,7 @@ static NAN_METHOD(PtyOpen) {
SetEnvironmentVariable(WINPTY_DBG_VARIABLE, debug ? "1" : NULL); // NULL = deletes variable

// Open a new pty session.
winpty_t *pc = winpty_open_use_own_datapipe(pipeName.c_str(), cols, rows);
winpty_t *pc = winpty_open_use_own_datapipe(pipeName, cols, rows);

// Error occured during startup of agent process.
assert(pc != nullptr);
Expand Down Expand Up @@ -247,25 +247,18 @@ static NAN_METHOD(PtyStartProcess) {
const wchar_t *cwd = to_wstring(String::Utf8Value(args[4]->ToString()));

// create environment block
wchar_t *env = NULL;
const Handle<Array> envValues = Handle<Array>::Cast(args[3]);
if(!envValues.IsEmpty()) {

std::wstringstream envBlock;

for(uint32_t i = 0; i < envValues->Length(); i++) {
std::wstring envValue(to_wstring(String::Utf8Value(envValues->Get(i)->ToString())));
envBlock << envValue << L' ';
}

std::wstring output = envBlock.str();

size_t count = output.size();
env = new wchar_t[count + 2];
wcsncpy(env, output.c_str(), count);

wcscat(env, L"\0");
}
std::wstring env;
const Handle<Array> envValues = Handle<Array>::Cast(args[3]);
uint32_t envValueCount = envValues->Length();
if (envValueCount > 0)
{
for(uint32_t i=0; i<envValueCount; i++)
{
env.append(to_wstring(String::Utf8Value(envValues->Get(i)->ToString())));
env.push_back(L'\0');
}
env.push_back(L'\0');
}

// use environment 'Path' variable to determine location of
// the relative path that we have recieved (e.g cmd.exe)
Expand Down Expand Up @@ -301,7 +294,6 @@ static NAN_METHOD(PtyStartProcess) {
delete filename;
delete cmdline;
delete cwd;
delete env;

if(!exception.IsEmpty()) {
return exception;
Expand Down