Yeah, missed the attach...
On Thu, Feb 5, 2015 at 11:39 AM, Abilio Marques <abili...@gmail.com> wrote: > Here the current code (missing the capture of the stdout). I send it as a > patch to the current trunk version (0d1d7f6481). > > > Ideas? > > On Sat, Jan 31, 2015 at 9:56 AM, Stephan Beal <sgb...@googlemail.com> > wrote: > >> On Sat, Jan 31, 2015 at 3:09 PM, Abilio Marques <abili...@gmail.com> >> wrote: >> >>> I think that adding the ability to capture the app stdout (and stderr) >>> would be a great thing. That way it could be even more powerful than git >>> hooks. >>> >> >> There is some code in fossil for capturing piped i/o, but i have no idea >> if it works on non-*nix: see src/popen.c. >> >> >>> But actually, I've never used TH1 before, so I don't even know if it's >>> possible to return values out of a function, nor if there is a limit on >>> strings length. >>> >> >> (A) you can return a string (because everything is a string in TH1) and >> (B) there is no inherent size limit other than the system's allocator. >> However, you might want to look into the full-fledged (optional) TCL >> support, as TH1 apps get tedious to debug once they're longer than 5 or 10 >> lines. (If you're just spawning a process and returning its output, though, >> you don't need much code.) That said, i cannot comment on the TCL bits - >> hopefully someone familiar with them can enlighten us on how best to go >> about it. >> >> >>> I want to share my working proof of concept with you guys, so you can >>> test it and give feedback on it. What is the best way to do it? >>> >>> >> >> Post it here and someone will certainly start playing with it. (i'm >> ruling myself out for the time being - i have nerve damage in my left arm >> from too much typing and am reduced to right-hand-only typing for the >> foreseeable future.) >> >> >>> How do I get allowed to push to a branch in the main repo? >>> >> >> http://www.fossil-scm.org/index.html/doc/trunk/www/copyright-release.html >> >> fill that out and send it (snail mail) to Richard (a.k.a. "drh") at the >> address on that form. >> >> Once he's got that on file, you'll be set up with commit access. >> >> :) >> >> -- >> ----- stephan beal >> http://wanderinghorse.net/home/stephan/ >> http://gplus.to/sgbeal >> "Freedom is sloppy. But since tyranny's the only guaranteed byproduct of >> those who insist on a perfect world, freedom will have to do." -- Bigby Wolf >> >> _______________________________________________ >> fossil-users mailing list >> fossil-users@lists.fossil-scm.org >> http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users >> >> >
Index: src/th_main.c ================================================================== --- src/th_main.c +++ src/th_main.c @@ -1335,10 +1335,100 @@ "synchronous requests are not yet implemented", 0, 0); blob_reset(&payload); return TH_ERROR; } } + +/* +** TH1 command: exec ?NOWAIT? cmd +** +** Runs a command +*/ +static int execCmd( + Th_Interp *interp, + void *p, + int argc, + const char **argv, + int *argl +){ + +#if defined(_WIN32) || defined(_WIN64) + STARTUPINFO si = {0}; + PROCESS_INFORMATION pi = {0}; +#else + pid_t pid; +#endif + + int wait = 1; + const char *cmd; + + /* check if parameters are there */ + if ( argc != 2 && argc != 3){ + return Th_WrongNumArgs(interp, "exec ?NOWAIT? CMD"); + } + + if ( argc == 3 && fossil_strcmp(argv[1], "NOWAIT") == 0 ){ + wait = 0; + cmd = argv[2]; + } else { + cmd = argv[1]; + } + +#if defined(_WIN32) || defined(_WIN64) + si.cb = sizeof(si); + + /* Start the child process. */ + if( !CreateProcess( NULL, /* No module name (use command line) */ + cmd, /* Command line */ + NULL, /* Process handle not inheritable */ + NULL, /* Thread handle not inheritable */ + FALSE, /* Set handle inheritance to FALSE */ + CREATE_NEW_PROCESS_GROUP, /* CREATE_NO_WINDOW = run with no window, see + no use in it if fossil is been used inside + a command line window anyway */ + NULL, /* Use parent's environment block */ + NULL, /* Use parent's starting directory */ + &si, /* Pointer to STARTUPINFO structure */ + &pi ) /* Pointer to PROCESS_INFORMATION structure */ + ) { + return TH_ERROR; + } + + if ( wait ){ + /* Wait until child process exits */ + WaitForSingleObject(pi.hProcess, INFINITE); + } + + /* Close process and thread handles */ + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + +#else + + pid = fork(); + + /* check if we're the child */ + if ( pid == 0 ){ + /* then run the command */ + execl("/bin/sh", "/bin/sh", "-c", cmd, NULL); + }else if( pid < 0 ){ + /* The fork failed */ + return TH_ERROR; + } + + /* we're still in the parent */ + if ( wait ){ + /* wait for the child */ + if ( waitpid (pid, NULL, 0) != pid ){ + return TH_ERROR; + } + } + + +#endif + return TH_OK; +} /* ** Attempts to open the configuration ("user") database. Optionally, also ** attempts to try to find the repository and open it. */ @@ -1403,10 +1493,11 @@ {"checkout", checkoutCmd, 0}, {"combobox", comboboxCmd, 0}, {"date", dateCmd, 0}, {"decorate", wikiCmd, (void*)&aFlags[2]}, {"enable_output", enableOutputCmd, 0}, + {"exec", execCmd, 0}, {"getParameter", getParameterCmd, 0}, {"globalState", globalStateCmd, 0}, {"httpize", httpizeCmd, 0}, {"hascap", hascapCmd, 0}, {"hasfeature", hasfeatureCmd, 0},
_______________________________________________ fossil-users mailing list fossil-users@lists.fossil-scm.org http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users