diff --git a/microscript/ILibDuktape_ChildProcess.c b/microscript/ILibDuktape_ChildProcess.c index a157e23..af96035 100644 --- a/microscript/ILibDuktape_ChildProcess.c +++ b/microscript/ILibDuktape_ChildProcess.c @@ -366,7 +366,7 @@ duk_ret_t ILibDuktape_ChildProcess_execFile(duk_context *ctx) { envargs[ecount] = (char*)duk_get_string(ctx, -2); - envargs[ecount + 1] = (char*)duk_get_string(ctx, -1); + envargs[ecount + 1] = (char*)duk_to_string(ctx, -1); ecount += 2; duk_pop_2(ctx); // [buf][env][enum] } @@ -428,6 +428,12 @@ void ILibDuktape_ChildProcess_PUSH(duk_context *ctx, void *chain) duk_push_int(ctx, 4); duk_put_prop_string(ctx, -2, "DETACHED"); duk_put_prop_string(ctx, -2, "SpawnTypes"); + + char flags[] = "exports.c_iflags = {'IGNBRK': 01, 'BRKINT': 02, 'IGNPAR': 04, 'PARMRK': 010,'INPCK': 020, 'ISTRIP': 040, 'INLCR': 0100, 'IGNCR': 0200, 'ICRNL': 0400, 'IUCLC': 01000, 'IXON': 02000, 'IXANY': 04000, 'IXOFF': 010000, 'IMAXBEL': 020000};\ + exports.c_oflags = {'OPOST': 001, 'OLCUC': 002, 'ONLCR': 004, 'OCRNL': 010, 'ONOCR': 020, 'ONLRET': 040, 'OFILL': 0100, 'OFDEL': 0200};\ + exports.c_lflags = {'ISIG': 001, 'ICANON': 002, 'ECHO': 010, 'ECHOE': 020, 'ECHOK': 040, 'ECHONL': 0100, 'NOFLSH': 0200, 'IEXTEN': 0400, 'TOSTOP': 0100000, 'ITOSTOP': 0100000}\ + "; + ILibDuktape_ModSearch_AddHandler_AlsoIncludeJS(ctx, flags, sizeof(flags) - 1); } void ILibDuktape_ChildProcess_Init(duk_context *ctx) { diff --git a/microstack/ILibProcessPipe.c b/microstack/ILibProcessPipe.c index b6b1eb0..e9b894f 100644 --- a/microstack/ILibProcessPipe.c +++ b/microstack/ILibProcessPipe.c @@ -887,7 +887,6 @@ ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_ CloseHandle(retVal->stdErr->mPipe_WriteEnd); retVal->stdErr->mPipe_WriteEnd = NULL; CloseHandle(retVal->stdIn->mPipe_ReadEnd); retVal->stdIn->mPipe_ReadEnd = NULL; } - retVal->hProcess = processInfo.hProcess; if (processInfo.hThread != NULL) CloseHandle(processInfo.hThread); retVal->PID = processInfo.dwProcessId; @@ -904,11 +903,54 @@ ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_ #ifndef __APPLE__ int pipe; struct winsize w; + struct termios tios; + char **options = (char**)envvars; + int flags = 0; + memset(&tios, 0, sizeof(tios)); + w.ws_row = CONSOLE_SCREEN_HEIGHT; w.ws_col = CONSOLE_SCREEN_WIDTH; w.ws_xpixel = 0; w.ws_ypixel = 0; - pid = forkpty(&pipe, NULL, NULL, &w); + + + while (options != NULL && options[0] != NULL) + { + if (strcasecmp("LINES", options[0]) == 0) + { + w.ws_row = atoi(options[1]); + } + else if (strcasecmp("COLUMNS", options[0]) == 0) + { + w.ws_col = atoi(options[1]); + } + else if (strcasecmp("c_iflag", options[0]) == 0) + { + flags = 1; + tios.c_iflag = (tcflag_t)atoi(options[1]); + } + else if (strcasecmp("c_oflag", options[0]) == 0) + { + flags = 1; + tios.c_oflag = (tcflag_t)atoi(options[1]); + } + else if (strcasecmp("c_cflag", options[0]) == 0) + { + flags = 1; + tios.c_cflag = (tcflag_t)atoi(options[1]); + } + else if (strcasecmp("c_lflag", options[0]) == 0) + { + flags = 1; + tios.c_lflag = (tcflag_t)atoi(options[1]); + } + + options += 2; + } + + + + pid = forkpty(&pipe, NULL, flags == 0 ? NULL : &tios, &w); retVal->PTY = pipe; retVal->stdIn = ILibProcessPipe_Pipe_CreateFromExistingWithExtraMemory(pipeManager, pipe, extraMemorySize); retVal->stdOut = ILibProcessPipe_Pipe_CreateFromExistingWithExtraMemory(pipeManager, pipe, extraMemorySize);